Frameworks & Platforms
Opik
Trace TokenLab OpenAI-compatible requests with Opik
Overview
Point an OpenAI client to TokenLab, then wrap that client with Opik to record calls.
Installation
pip install opik openaiEnvironment
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
export OPIK_PROJECT_NAME="tokenlab-integration-demo"Wrap the OpenAI Client
Configure Opik before running this example: Opik Cloud requires OPIK_API_KEY and, when needed, OPIK_WORKSPACE. For an existing self-hosted deployment, set OPIK_URL_OVERRIDE to its API URL, such as http://localhost:5173/api. See the Opik configuration guide.
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)Log a Chat Completion
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)Endpoint Notes
This setup traces the OpenAI-compatible SDK path. If you use TokenLab native endpoints outside the OpenAI SDK, instrument that client or workflow separately.