Overview
The OpenAI Agents SDK can use TokenLab through an OpenAI-compatible client and OpenAIChatCompletionsModel.
Type: Python Agent SDKPrimary Path: OpenAI-compatible chat completionsSupport Confidence: Supported chat-completions path
Environment
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
export TOKENLAB_BASE_URL="https://api.tokenlab.sh/v1"
export TOKENLAB_MODEL="gpt-5.4-mini"
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.4-mini"),
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.