> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenLLMetry

> 使用 OpenLLMetry 追蹤 TokenLab 與 OpenAI 相容的請求

## 概覽

OpenLLMetry 的 OpenAI 檢測（instrumentation）功能可追蹤透過官方 OpenAI SDK 發出的呼叫。請將該 SDK 設定為使用 TokenLab 的 `/v1` 基礎 URL。

<Note>
  **類型**: 可觀測性 (Observability)

  **主要路徑**: OpenAI SDK 檢測

  **支援信心**: 支援與 OpenAI 相容的可觀測性路徑
</Note>

## 安裝

```bash theme={null}
pip install opentelemetry-instrumentation-openai openai
```

## 環境變數

```bash theme={null}
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
```

## 範例

```python theme={null}
import os

from openai import OpenAI
from opentelemetry.instrumentation.openai import OpenAIInstrumentor

OpenAIInstrumentor().instrument()

client = OpenAI(
    api_key=os.environ["TOKENLAB_API_KEY"],
    base_url="https://api.tokenlab.sh/v1",
)

client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "Trace this request"}],
)
```

## 端點注意事項

請針對與 OpenAI SDK 相容的 TokenLab 呼叫使用此路徑。若要使用 TokenLab 原生端點，請檢測實際發送這些請求的 HTTP 或 SDK 客戶端。
