Connect OpenAI Agents SDK to byesu API
Run Python's OpenAI Agents SDK (openai-agents) against byesu to build multi-agent handoffs, guardrails, and @function_tool workflows backed by Claude 5.5, GPT-6.2, DeepSeek V4, Gemini 4, or Grok with a single pay-as-you-go API key.
Quick configuration
AsyncOpenAIbase_url:https://byesu.com/v1- Cross-vendor model wrapper:
OpenAIChatCompletionsModel(claude-opus-5-5,claude-sonnet-5-5,deepseek-v4-pro,gemini-4-argon,gpt-6.2-sol) - OpenAI
/v1/responseswrapper:OpenAIResponsesModel(gpt-6.2-sol,gpt-6.2-astra) - Disable hosted trace 401s: call
set_tracing_disabled(True)(when not providing a separate OpenAI tracing key)
Prerequisites
- Create an
sk-...token in the byesu Console under the defaultautogroup (see Choosing a Group). - Install
openai-agentsand export your key:
pip install openai-agents
export BYESU_API_KEY="sk-your-byesu-token"Production Gotcha #1: Disable Default OpenAI Trace Export
By default, openai-agents uploads background execution traces to OpenAI's hosted tracing backend (api.openai.com) using OPENAI_API_KEY. If you run exclusively with BYESU_API_KEY (or point OPENAI_API_KEY at a gateway token), the background trace exporter will log repeated 401 Unauthorized warnings even though your agent calls succeed.
Call set_tracing_disabled(True) at startup (or set export OPENAI_AGENTS_DISABLE_TRACING=1 in your environment) whenever you do not supply a separate official OpenAI key for hosted trace ingestion:
from agents import set_tracing_disabled
set_tracing_disabled(True)Option 1: Cross-Vendor Agents & Handoffs (OpenAIChatCompletionsModel)
Pair AsyncOpenAI (base_url="https://byesu.com/v1") with OpenAIChatCompletionsModel to run any model on byesu — and even hand off tasks across vendors in a single run:
import asyncio
import os
from openai import AsyncOpenAI
from agents import (
Agent,
OpenAIChatCompletionsModel,
Runner,
function_tool,
set_tracing_disabled,
)
# Silence background api.openai.com trace exporter 401 warnings
set_tracing_disabled(True)
client = AsyncOpenAI(
base_url="https://byesu.com/v1",
api_key=os.environ["BYESU_API_KEY"],
timeout=120.0,
)
@function_tool
def fetch_error_budget(service: str) -> str:
"""Return remaining 30-day SLO error budget for a production service."""
return f"{service}: 18.4% error budget remaining (p95 latency 210ms)."
sre_specialist = Agent(
name="SRESpecialist",
instructions="Analyze SLO telemetry and give a concrete rollout go/no-go decision.",
model=OpenAIChatCompletionsModel(
model="claude-opus-5-5", # also works with "deepseek-v4-pro", "gemini-4-argon", "gpt-6.2-sol"
openai_client=client,
),
tools=[fetch_error_budget],
)
triage_agent = Agent(
name="TriageRouter",
instructions="Route reliability and deployment questions to SRESpecialist.",
model=OpenAIChatCompletionsModel(
model="gemini-3.8-flash",
openai_client=client,
),
handoffs=[sre_specialist],
)
async def main() -> None:
result = await Runner.run(
triage_agent,
"Check checkout-api error budget and tell me if we should freeze Friday deploys.",
)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())Option 2: OpenAI /v1/responses Agents (OpenAIResponsesModel)
When running GPT-6.2 models (gpt-6.2-sol, gpt-6.2-astra) that leverage OpenAI's /v1/responses protocol, wrap the same AsyncOpenAI client in OpenAIResponsesModel:
import asyncio
import os
from openai import AsyncOpenAI
from agents import Agent, OpenAIResponsesModel, Runner, set_tracing_disabled
set_tracing_disabled(True)
client = AsyncOpenAI(
base_url="https://byesu.com/v1",
api_key=os.environ["BYESU_API_KEY"],
timeout=120.0,
)
planner = Agent(
name="ArchitecturePlanner",
instructions="Design pragmatic, migration-safe backend schemas.",
model=OpenAIResponsesModel(
model="gpt-6.2-sol",
openai_client=client,
),
)
async def main() -> None:
result = await Runner.run(
planner,
"Propose a zero-downtime PostgreSQL partitioning rollout for an append-only audit table.",
)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())(Keep non-OpenAI models such as claude-opus-5-5, deepseek-v4-pro, and gemini-4-argon on OpenAIChatCompletionsModel.)
Production Engineering Notes
- Omit fixed
temperatureinModelSettings: Claude 5.5 (2026-10-21schema) and GPT-6.2 reasoning models reject legacytemperature/top_poverrides with HTTP400. LeaveModelSettingswithouttemperature(Claude 400 sampling fix,reasoning_effortvalues). - Client timeouts: Pass
timeout=120.0(or higher) toAsyncOpenAIso deep reasoning turns inside multi-stepRunner.runloops do not time out prematurely. - Token groups & billing: Default
autotokens cover Claude, GPT, Gemini, DeepSeek, and Grok; create separate tokens inGlm(glm-5.3),Kimi(kimi-k3), ormedia(gpt-image-2,gemini-3.1-flash-image-ultra) when needed. All text/code models bill pay-as-you-go per token with live rates in the byesu Console after sign-in.
Troubleshooting & Benchmarks
- Background
401tracing warnings in logs: callset_tracing_disabled(True)or exportOPENAI_AGENTS_DISABLE_TRACING=1(OpenAI 401 fix). 404/no available channel: confirmbase_url="https://byesu.com/v1", useOpenAIChatCompletionsModelfor non-OpenAI models, and verify the exact console model ID (no available channel).- Stateful
previous_response_iderrors: see previous response not found. 429& live benchmarks: check OpenAI 429 rate limit vs quota and weekly production benchmarks.