TokenLab

Frameworks & Platforms

Langfuse

Trace TokenLab OpenAI-compatible requests with Langfuse

Overview

Langfuse can trace OpenAI SDK calls after the SDK Base URL is changed to TokenLab /v1.

Installation

pip install langfuse openai

Environment

export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_BASE_URL="https://cloud.langfuse.com"
export TOKENLAB_API_KEY="sk-your-tokenlab-key"

Example

import os

from langfuse import get_client, observe
from langfuse.openai import OpenAI

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


@observe()
def story():
    return client.chat.completions.create(
        model="claude-sonnet-5",
        messages=[{"role": "user", "content": "Write a short haiku."}],
    ).choices[0].message.content


print(story())
get_client().flush()

Endpoint Notes

This page covers Langfuse tracing for the OpenAI SDK path. If your application uses TokenLab native Responses, Anthropic Messages, or Gemini endpoints, make sure your instrumentation captures that client call path.

On this page