> ## Documentation Index
> Fetch the complete documentation index at: https://developers.meshapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> Run the OpenAI Agents SDK on Mesh — both the default Responses path and the chat-completions wrapper, plus the tracing setting you must change.

The OpenAI Agents SDK is built on the OpenAI client, so pointing it at Mesh is a base-URL change. Mesh serves both the Responses API and chat completions, so **either** path works — unlike most OpenAI-compatible gateways, you do not have to force the SDK off its default.

## Install

```bash theme={null}
pip install openai-agents
```

## Connect

**Default (Responses API)**

```python theme={null}
import os

from agents import (
    Agent,
    set_default_openai_api,
    set_default_openai_client,
    set_tracing_disabled,
)
from openai import AsyncOpenAI

set_tracing_disabled(True)

client = AsyncOpenAI(
    base_url="https://api.meshapi.ai/v1",
    api_key=os.environ["MESH_API_KEY"],    # rsk_...
)
set_default_openai_client(client)
set_default_openai_api("responses")        # the SDK's own default

agent = Agent(name="support", instructions="Be concise.", model="auto")
```

Mesh serves `POST /v1/responses`, so the SDK's native path works. A model without Responses support returns `400 model_capability_not_supported`; `auto` resolves to one that supports it.

**Chat completions**

```python theme={null}
import os

from agents import Agent, OpenAIChatCompletionsModel, set_tracing_disabled
from openai import AsyncOpenAI

set_tracing_disabled(True)

client = AsyncOpenAI(
    base_url="https://api.meshapi.ai/v1",
    api_key=os.environ["MESH_API_KEY"],    # rsk_...
)

agent = Agent(
    name="support",
    instructions="Be concise.",
    model=OpenAIChatCompletionsModel(model="auto", openai_client=client),
)
```

Pin this wrapper when you want `POST /v1/chat/completions` specifically — for example to use a model that has no Responses support.

> [!WARNING]
>
> Call `set_tracing_disabled(True)`, or set `OPENAI_AGENTS_DISABLE_TRACING=1`.
>
> The SDK uploads traces to OpenAI's own backend by default, authenticated with `OPENAI_API_KEY`. Pointing the SDK at Mesh does **not** redirect tracing. Left on without an OpenAI key it logs export errors on every run; left on *with* one, it ships your agents' prompts and tool calls to OpenAI.

## Tool calling

```python theme={null}
from agents import Runner, function_tool


@function_tool
def get_shipment_status(order_id: str) -> dict:
    """Look up the shipment status of an order."""
    book = {"A-1042": {"state": "in transit", "eta_days": 2}}
    if order_id in book:
        return {"status": "success", "order_id": order_id, **book[order_id]}
    return {"status": "error", "error_message": f"No order {order_id}."}


agent = Agent(
    name="support",
    instructions="Use the tool for order questions. Be concise.",
    model="auto",
    tools=[get_shipment_status],
)

result = await Runner.run(agent, "What's the shipment status of order A-1042?")
print(result.final_output)
```

`result.new_items` carries the `ToolCallItem` and `ToolCallOutputItem` entries if you need to inspect the tool exchange. Handoffs and guardrails work unchanged — they are SDK-side features and never reach the model API.

## Caveats

Everything in [Caveats that apply to every framework](https://developers.meshapi.ai/agent/frameworks.md#caveats-that-apply-to-every-framework) applies here.

## Related

* [Agent frameworks](https://developers.meshapi.ai/agent/frameworks.md) — the shared pattern and compatibility matrix
* [Auto-routing](https://developers.meshapi.ai/docs/capabilities/auto-routing.md) — how `auto` picks a model
* [Authentication](https://developers.meshapi.ai/docs/getting-started/authentication.md) — `rsk_` keys versus `mak_` admin keys


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.