---
title: "OpenAI Agents SDK with a custom OpenAI-compatible provider"
description: "Use the OpenAI Agents SDK for Python with BroadNet Inference through AsyncOpenAI and OpenAIChatCompletionsModel, and turn off tracing that needs an OpenAI key."
url: https://broadrouter.com/guides/openai-agents-sdk-custom-provider/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Run the OpenAI Agents SDK on BroadNet Inference

Updated 2026-11-16

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.

```bash
pip install openai-agents
export BROADNET_API_KEY='your-broadnet-key'
```

2.  **Create the client, model and agent.**

```python
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())
```

3.  **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:

```python
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](https://broadrouter.com/models/glm-5.3/) | Tools and structured output listed; 1M context |
| Image input with tools | [Qwen3.8 27B](https://broadrouter.com/models/qwen3.8-27b/) | 262K context; tested in Arabic |
| Long-running agents on a flat rate | [DeepSeek V4.1 Flash](https://broadrouter.com/models/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](https://broadrouter.com/pricing/).

## 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](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **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](https://broadrouter.com/guides/errors-and-retries/).
-   **Parallel agents on a plan.** An [unlimited plan session](https://broadrouter.com/guides/unlimited-llm-api-sessions/) 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](https://broadrouter.com/blog/run-parallel-coding-agents-flat-rate/).

## Terms in this guide

[Tool calling](https://broadrouter.com/glossary/tool-calling/)

Tool calling, also called function calling, is an LLM API feature in which the model returns a structured request to run a function the developer has defined, with JSON arguments. The application runs the function and sends the result back; the model never runs code itself.

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Structured output](https://broadrouter.com/glossary/structured-output/)

Structured output is an LLM API feature that constrains a model's reply to a format the developer specifies, usually a JSON Schema, so code can parse it reliably. It is stricter than JSON mode, which guarantees valid JSON but not a particular shape.

[Chat Completions API](https://broadrouter.com/glossary/chat-completions-api/)

The Chat Completions API is OpenAI's HTTP endpoint, POST /v1/chat/completions, that takes a model name and a list of role-tagged messages and returns the model's next message. Its request and response shape became the common format that OpenAI-compatible providers and SDKs reuse.

[API key](https://broadrouter.com/glossary/api-key/)

An API key is a secret string that identifies and authorizes a client calling an API. LLM APIs usually expect it in an Authorization: Bearer header, and anyone who holds the key can make requests that are billed to the account that owns it.

[Concurrency](https://broadrouter.com/glossary/concurrency/)

Concurrency is the number of requests a client has in flight at the same time. LLM APIs often cap it per key or plan, separately from requests per minute, because each open request holds GPU capacity until its response has finished.

[Guardrails](https://broadrouter.com/glossary/guardrails/)

Guardrails are checks that an application runs around a language model call to keep it within set limits. Input guardrails screen what goes into the model, output guardrails check what comes out, and tool guardrails validate actions before they run. A failed check blocks, rewrites or flags the request.

[OpenAI-compatible API](https://broadrouter.com/glossary/openai-compatible-api/)

An OpenAI-compatible API is an HTTP API that accepts the same request and response formats as the OpenAI API, such as POST /v1/chat/completions, so OpenAI SDKs and tools can use it by changing only the base URL, the API key and the model name.

## 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.

## Related guides

-   [Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/)
-   [How the unlimited LLM API plans work for agents](https://broadrouter.com/guides/unlimited-llm-api-sessions/)
-   [Why a reasoning model returns an empty answer](https://broadrouter.com/guides/reasoning-tokens-empty-response/)
-   [Route LiteLLM to BroadNet Inference (SDK and proxy)](https://broadrouter.com/guides/litellm-proxy-custom-provider/)
-   [All tools that work with BroadNet Inference](https://broadrouter.com/integrations/): SDKs, coding agents, chat UIs and automation tools, with exact settings for each

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-openai-agents-sdk-custom-provider&utm_content=page-cta) ·

**Sources**

-   [OpenAI Agents SDK docs, Models (non-OpenAI providers) (checked 2026-11-14)](https://openai.github.io/openai-agents-python/models/)
-   [PyPI, openai-agents package (0.24, Python 3.10+, checked 2026-11-14)](https://pypi.org/project/openai-agents/)
-   [BroadNet Inference API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-openai-agents-sdk-custom-provider&utm_content=sources)
