> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/docs/_mcp/server.

# OpenAI Agents (gateway)

> Set up OpenAI Agents SDK with the Respan gateway.

Route LLM calls through the Respan gateway to use 1000+ models from different providers. Only your Respan API key is needed — no separate provider keys required.

## Setup

#### Install packages

**`Python`**

```bash Python
pip install openai-agents
```

**`TypeScript`**

```bash TypeScript
npm install @openai/agents openai
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

No `OPENAI_API_KEY` needed — the Respan gateway handles provider authentication.

#### Point to the Respan gateway

**`Python`**

```python Python
import os
import asyncio
from openai import AsyncOpenAI
from agents import (
    Agent,
    Runner,
    set_default_openai_api,
    set_default_openai_client,
    set_tracing_disabled,
)

client = AsyncOpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url="https://api.respan.ai/api",
)
set_default_openai_client(client)
set_default_openai_api("chat_completions")
set_tracing_disabled(True)

agent = Agent(
    name="Assistant",
    model="gpt-5.5",
    instructions="You only respond in haikus.",
)

async def main():
    result = await Runner.run(agent, "Tell me about recursion.")
    print(result.final_output)

asyncio.run(main())
```

**`TypeScript`**

```typescript TypeScript
import {
  Agent,
  OpenAIProvider,
  run,
  setDefaultModelProvider,
  setOpenAIAPI,
  setTracingDisabled,
} from "@openai/agents";

setDefaultModelProvider(
  new OpenAIProvider({
    apiKey: process.env.RESPAN_API_KEY,
    baseURL: "https://api.respan.ai/api",
  })
);
setOpenAIAPI("chat_completions");
setTracingDisabled(true);

const agent = new Agent({
  name: "Assistant",
  model: "gpt-5.5",
  instructions: "You only respond in haikus.",
});

const result = await run(agent, "Tell me about recursion.");
console.log(result.finalOutput);
```

> **Note**
>
> OpenAI Agents defaults to the Responses API, which the gateway serves for OpenAI models only. Set the SDK to `chat_completions` so the same agent can also run non-OpenAI models, such as the Claude example below.

## Switch models

Change the `model` parameter on any agent to use 1000+ models from different providers through the same gateway.

```python
agent = Agent(
    name="Assistant",
    model="claude-sonnet-4-5-20250929",  # Use Anthropic via gateway
    instructions="You are a helpful assistant.",
)
```

See the [full model list](https://platform.respan.ai/platform/models).