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

# Claude Agent SDK (gateway)

> Set up Claude Agent SDK with the Respan gateway.

Route Claude Agent SDK calls through the Respan gateway. Only your `RESPAN_API_KEY` is needed — no separate `ANTHROPIC_API_KEY` required.

## Setup

#### Install packages

**`Python`**

```bash Python
pip install claude-agent-sdk
```

**`TypeScript`**

```bash TypeScript
npm install @anthropic-ai/claude-agent-sdk
```

#### Set environment variables

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

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

#### Point Claude Agent SDK to the Respan gateway

**`Python`**

```python Python
import os
import asyncio

import claude_agent_sdk
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = "https://api.respan.ai/api"

async def main():
    options = ClaudeAgentOptions(
        model="sonnet",
        max_turns=1,
        env={
            "ANTHROPIC_API_KEY": respan_api_key,
            "ANTHROPIC_AUTH_TOKEN": respan_api_key,
            "ANTHROPIC_BASE_URL": f"{respan_base_url}/anthropic/",
        },
    )

    async for message in claude_agent_sdk.query(
        prompt="Explain tracing in one sentence.",
        options=options,
    ):
        if isinstance(message, ResultMessage):
            print(message.result)

asyncio.run(main())
```

**`TypeScript`**

```typescript TypeScript
import * as _ClaudeAgentSDK from "@anthropic-ai/claude-agent-sdk";

const ClaudeAgentSDK = { ..._ClaudeAgentSDK };
const respanApiKey = process.env.RESPAN_API_KEY!;
const respanBaseUrl = "https://api.respan.ai/api";

const response = await ClaudeAgentSDK.query({
  prompt: "Explain tracing in one sentence.",
  options: {
    model: "sonnet",
    maxTurns: 1,
    env: {
      ANTHROPIC_API_KEY: respanApiKey,
      ANTHROPIC_AUTH_TOKEN: respanApiKey,
      ANTHROPIC_BASE_URL: `${respanBaseUrl}/anthropic/`,
    },
  },
});

for await (const message of response) {
  if (message.type === "result") {
    console.log(message.result);
  }
}
```

> **Note**
>
> Claude Agent SDK expects Anthropic-shaped environment variable names in its subprocess configuration. These examples map those names to `RESPAN_API_KEY`; they do not require a separate Anthropic provider key.

## Switch models

Change the `model` parameter to use different Claude models through the same gateway.

```python
model = "claude-sonnet-4-5-20250929"
# model = "claude-haiku-4-5-20251001"
# model = "claude-opus-4-5-20251101"

options = ClaudeAgentOptions(
    model=model,
    max_turns=1,
    env={
        "ANTHROPIC_API_KEY": respan_api_key,
        "ANTHROPIC_AUTH_TOKEN": respan_api_key,
        "ANTHROPIC_BASE_URL": f"{respan_base_url}/anthropic/",
    },
)
```

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