Integrations
OpenAI Agents SDK
The OpenAI Agents SDK in Python with AI Tokens: an agent on chat completions, with tracing switched off.
Last updated: 2026-10-11
pip install openai-agents
export API_KEY="sk-at-…"
An agent with a tool
import os
from agents import Agent, ModelSettings, OpenAIChatCompletionsModel, Runner, function_tool, set_tracing_disabled
from openai import AsyncOpenAI
# Traces go to OpenAI's servers by default: switch them off (see Tracing below).
set_tracing_disabled(True)
client = AsyncOpenAI(
base_url="https://api.aitokens.ch/v1",
api_key=os.environ["API_KEY"],
)
@function_tool
def get_weather(city: str) -> str:
"""Current weather for a city."""
return f"{city}: 14 °C, light rain"
agent = Agent(
name="Assistant",
instructions="Answer in one sentence.",
model=OpenAIChatCompletionsModel(model="qwen3.8-27b", openai_client=client),
model_settings=ModelSettings(max_tokens=2048),
tools=[get_weather],
)
result = Runner.run_sync(agent, "What is the weather in Lugano?")
print(result.final_output)
What came back on qwen3.8-27b:
The weather in Lugano is currently 14 °C with light rain.
The agent called get_weather, read its result and answered with it.
Chat completions for every agent
The SDK uses OpenAI's Responses API by default. Give each agent an
OpenAIChatCompletionsModel, as above, or set it once for every agent:
from agents import set_default_openai_api, set_default_openai_client
set_default_openai_client(client, use_for_tracing=False)
set_default_openai_api("chat_completions")
We ran the same agent through the Responses API too, on qwen3.6-35b. It
answered "I do not have access to real-time weather data": AI Tokens's
Responses API did not read the tool's result on 11 October 2026, and it has no
streaming.
Tracing
Unless tracing is disabled, the SDK uploads traces to OpenAI's servers. It
signs them with the key in OPENAI_API_KEY, or with the key of the client
given to set_default_openai_client. Either can be your AI Tokens key, which
would then be sent to OpenAI. Call set_tracing_disabled(True), or pass
use_for_tracing=False to set_default_openai_client and send traces to a
processor of your own.
Limits
max_tokensup to 8192. A higher value is refused with422.- Models with tools:
qwen3.8-27b,qwen3.6-35b,qwen3-coder-30b,gpt-oss-120b,gemma-4-26bandministral-3-14breturned tool calls on 11 October 2026. See Which model.