---
title: "Claude Agent SDK (gateway)"
description: "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` is required.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Claude Agent SDK integration.
Follow https://www.respan.ai/docs/integrations/gateway/claude-agent-sdk.md
```

## Setup

<Steps>
<Step title="Install packages">

<Tabs>
<Tab title={"Python"}>

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

</Tab>
<Tab title={"TypeScript"}>

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

</Tab>
</Tabs>

</Step>

<Step title="Set environment variables">

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

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

</Step>

<Step title="Point Claude Agent SDK to the Respan gateway">

<Tabs>
<Tab title={"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://gateway.respan.ai"

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

</Tab>
<Tab title={"TypeScript"}>

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

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

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);
  }
}
```

</Tab>
</Tabs>

<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.
</Note>

</Step>
</Steps>

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