BroadRouter

Run the OpenAI Agents SDK on BroadNet Inference

Updated

Create an AsyncOpenAI client with base_url https://inference.broadnet.ai/v1 and your BroadNet key, wrap it in OpenAIChatCompletionsModel with a model ID such as broadnet/glm-5.3, and pass that model to your Agent. Call set_tracing_disabled(True) unless you have a separate OpenAI key for tracing.

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

  1. Install the SDK. It needs Python 3.10 or newer.
pip install openai-agents
export BROADNET_API_KEY='your-broadnet-key'
  1. 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())
  1. Run it. The agent should call get_order_status and answer from its result.

Three ways to wire the provider

The SDK docs list these built-in options:

  • Per agent: pass OpenAIChatCompletionsModel as Agent.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 with set_default_openai_api("chat_completions").
  • Per run: pass a custom ModelProvider in RunConfig(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 OpenAIChatCompletionsModel or set_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 toward max_tokens. If you set ModelSettings(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.gather need one session each, or they queue. See running parallel agents on a flat rate.

Questions

Why do I get 404 errors from the Agents SDK with a custom base URL?

The SDK uses the Responses API by default. BroadNet serves chat completions. Use OpenAIChatCompletionsModel, or call set_default_openai_api("chat_completions") if you configure the client through environment variables.

Why does the Agents SDK complain about tracing?

Tracing uploads to OpenAI and needs a key from platform.openai.com. The SDK docs recommend set_tracing_disabled() when you don't have one, or a different tracing processor.

Can I configure the Agents SDK with environment variables only?

Yes. Set OPENAI_BASE_URL to https://inference.broadnet.ai/v1 and OPENAI_API_KEY to your BroadNet key, then call set_default_openai_api("chat_completions") and set_tracing_disabled(True). OPENAI_DEFAULT_MODEL sets the model for agents that don't name one.

How many plan sessions does a multi-agent run need?

One per request that runs at the same time. Handoffs run one agent after another, so one session is enough. Agents run in parallel with asyncio.gather need one session each.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity