> ## 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.

# Opik

> Theo dõi các yêu cầu tương thích với OpenAI của TokenLab bằng Opik

## Tổng quan

Opik có thể ghi nhật ký các lệnh gọi TokenLab bằng cách bao bọc (wrap) một client OpenAI trỏ đến endpoint tương thích với OpenAI của TokenLab.

<Note>
  **Loại**: Khả năng quan sát (Observability)

  **Đường dẫn chính**: Trình bao bọc theo dõi OpenAI SDK

  **Độ tin cậy hỗ trợ**: Đường dẫn theo dõi tương thích với OpenAI được hỗ trợ
</Note>

## Cài đặt

```bash theme={null}
pip install opik openai
```

## Môi trường

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

## Bao bọc OpenAI Client

```python theme={null}
import os

from openai import OpenAI
from opik.integrations.openai import track_openai

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

openai_client = track_openai(client)
```

## Ghi nhật ký Chat Completion

```python theme={null}
completion = openai_client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[
        {"role": "user", "content": "Summarize why LLM observability matters."}
    ],
)

print(completion.choices[0].message.content)
```

## Lưu ý về Endpoint

Thiết lập này theo dõi đường dẫn SDK tương thích với OpenAI. Nếu bạn sử dụng các endpoint gốc của TokenLab bên ngoài OpenAI SDK, hãy thực hiện instrument cho client hoặc quy trình làm việc đó một cách riêng biệt.
