The OpenAI Agents SDK is a Python framework for agents with tools, handoffs and guardrails. Its docs describe how to plug in non-OpenAI providers. For an OpenAI-compatible API such as BroadNet Inference, you give the SDK your own AsyncOpenAI client and use the Chat Completions model class. The SDK defaults to the Responses API, which many providers don’t serve.
Setup
- Install the SDK. It needs Python 3.10 or newer.
pip install openai-agents
export BROADNET_API_KEY='your-broadnet-key'
- Create the client, model and agent.
import asyncio
import os
from agents import (
Agent,
AsyncOpenAI,
OpenAIChatCompletionsModel,
Runner,
function_tool,
set_tracing_disabled,
)
set_tracing_disabled(disabled=True) # tracing needs a platform.openai.com key
client = AsyncOpenAI(
base_url="https://inference.broadnet.ai/v1",
api_key=os.environ["BROADNET_API_KEY"],
)
model = OpenAIChatCompletionsModel(model="broadnet/glm-5.3", openai_client=client)
@function_tool
def get_order_status(order_id: str) -> str:
"""Look up an order."""
return f"Order {order_id}: shipped"
agent = Agent(
name="Support agent",
instructions="Answer briefly. Use tools when you need order data.",
model=model,
tools=[get_order_status],
)
async def main():
result = await Runner.run(agent, "Where is order 4471?")
print(result.final_output)
asyncio.run(main())
- Run it. The agent should call
get_order_statusand answer from its result.
Three ways to wire the provider
The SDK docs list these built-in options:
- Per agent: pass
OpenAIChatCompletionsModelasAgent.model, as above. Use this when different agents use different providers. - Global default:
set_default_openai_client(client)makes your client the default. Pair it withset_default_openai_api("chat_completions"). - Per run: pass a custom
ModelProviderinRunConfig(model_provider=...).
The global default looks like this:
import os
from agents import (
Agent,
AsyncOpenAI,
set_default_openai_api,
set_default_openai_client,
set_tracing_disabled,
)
client = AsyncOpenAI(base_url="https://inference.broadnet.ai/v1", api_key=os.environ["BROADNET_API_KEY"])
set_default_openai_client(client, use_for_tracing=False)
set_default_openai_api("chat_completions")
set_tracing_disabled(True)
agent = Agent(name="Assistant", instructions="Be brief.", model="broadnet/glm-5.3")
With only environment variables, set OPENAI_BASE_URL=https://inference.broadnet.ai/v1 and OPENAI_API_KEY to your BroadNet key, then make the same set_default_openai_api and set_tracing_disabled calls.
When you route through Chat Completions, the SDK docs say it silently drops Responses-only fields, such as previous_response_id, conversation_id and prompt. To get an error instead, set strict_feature_validation=True on OpenAIProvider. Keep conversation state in your own code, for example by passing the previous result’s input list into the next run. Hosted OpenAI tools such as web search and file search don’t exist on other providers. Use function_tool for anything the agent should call.
Tracing
Tracing is on by default and sends traces to OpenAI. The SDK docs say that without an API key from platform.openai.com you should disable it with set_tracing_disabled() or set up a different tracing processor. If you do have an OpenAI key, you can keep tracing on and pass that key with set_tracing_export_api_key(...). The SDK uses it only for uploading traces. Your BroadNet key won’t work for it.
Which model to pick
| Agent type | Model | Notes |
|---|---|---|
| Tool-using agents | GLM 5.3 | Tools and structured output listed; 1M context |
| Image input with tools | Qwen3.8 27B | 262K context; tested in Arabic |
| Long-running agents on a flat rate | DeepSeek V4.1 Flash | Unlimited plans; tools not listed by BroadNet |
The SDK docs warn that some providers don’t support JSON-schema structured outputs. If you set output_type on an agent, use GLM 5.3 or Qwen3.8 27B. Compare prices on the pricing page.
Troubleshooting
- 401. The BroadNet key is wrong, expired, or out of pay-as-you-go allowance. Tracing errors in the logs are separate: they mean tracing is still on without an OpenAI key.
- 404 or “not found”. You are probably on the Responses API. Use
OpenAIChatCompletionsModelorset_default_openai_api("chat_completions"). If that’s set, check the model ID matches BroadNet’s exactly. Paid models need a top-up; the $5 credit covers Gemma 4 VL 26B and the two Transcribe models. - Empty
final_output. Reasoning counts towardmax_tokens. If you setModelSettings(max_tokens=...), raise it. Why answers come back empty. - 429. A pay-as-you-go key allows 30 requests a minute and 4 at once. Each tool round-trip is a new request. See errors and retries.
- Parallel agents on a plan. An unlimited plan session runs one request at a time. Agents launched together with
asyncio.gatherneed one session each, or they queue. See running parallel agents on a flat rate.
