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

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

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.

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.