Skip to main content

Overview

Opik can log TokenLab calls by wrapping an OpenAI client that points to TokenLab’s OpenAI-compatible endpoint.
Type: ObservabilityPrimary Path: OpenAI SDK tracing wrapperSupport Confidence: Supported OpenAI-compatible tracing path

Installation

pip install opik openai

Environment

export TOKENLAB_API_KEY="sk-your-tokenlab-key"
export OPIK_PROJECT_NAME="tokenlab-integration-demo"

Wrap the OpenAI Client

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.