Claude Agent SDK (gateway)

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

Setup

1

Install packages

$pip install claude-agent-sdk
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

No ANTHROPIC_API_KEY needed — the Respan gateway handles provider authentication.

3

Point Claude Agent SDK to the Respan gateway

1import os
2import asyncio
3
4import claude_agent_sdk
5from claude_agent_sdk import ClaudeAgentOptions, ResultMessage
6
7respan_api_key = os.environ["RESPAN_API_KEY"]
8respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")
9
10async def main():
11 options = ClaudeAgentOptions(
12 model="sonnet",
13 max_turns=1,
14 env={
15 "ANTHROPIC_API_KEY": respan_api_key,
16 "ANTHROPIC_AUTH_TOKEN": respan_api_key,
17 "ANTHROPIC_BASE_URL": f"{respan_base_url}/anthropic/",
18 },
19 )
20
21 async for message in claude_agent_sdk.query(
22 prompt="Explain tracing in one sentence.",
23 options=options,
24 ):
25 if isinstance(message, ResultMessage):
26 print(message.result)
27
28asyncio.run(main())

Switch models

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

1options = ClaudeAgentOptions(model="claude-sonnet-4-5-20250929", ...)
2options = ClaudeAgentOptions(model="claude-haiku-4-5-20251001", ...)
3options = ClaudeAgentOptions(model="claude-opus-4-5-20251101", ...)

See the full model list.