Frameworks & Platforms
OpenAI Agents SDK
Use TokenLab models with the OpenAI Agents SDK
Overview
Create an OpenAI-compatible TokenLab client and pass it to OpenAIChatCompletionsModel.
Environment
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
export TOKENLAB_BASE_URL="https://api.tokenlab.sh/v1"
export TOKENLAB_MODEL="gpt-5.6-luna"Example
import asyncio
import os
from openai import AsyncOpenAI
from agents import Agent, OpenAIChatCompletionsModel, Runner, set_tracing_disabled
client = AsyncOpenAI(
base_url=os.getenv("TOKENLAB_BASE_URL", "https://api.tokenlab.sh/v1"),
api_key=os.environ["TOKENLAB_API_KEY"],
)
set_tracing_disabled(disabled=True)
async def main():
agent = Agent(
name="Assistant",
instructions="You are concise and practical.",
model=OpenAIChatCompletionsModel(
model=os.getenv("TOKENLAB_MODEL", "gpt-5.6-luna"),
openai_client=client,
),
)
result = await Runner.run(agent, "Explain custom model providers in one paragraph.")
print(result.final_output)
asyncio.run(main())Scope
This path uses Chat Completions compatibility. TokenLab's native Responses endpoint is available at https://api.tokenlab.sh/v1/responses, but SDK features that depend on OpenAI-specific Responses semantics should be verified with the exact model and workflow before production use.