---
title: "Anthropic SDK (gateway)"
description: "Set up Anthropic SDK with the Respan gateway."
---

Route Anthropic 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 Anthropic SDK integration.
Follow https://www.respan.ai/docs/integrations/gateway/anthropic-sdk.md
```

## Setup

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

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

```bash
pip install anthropic
```

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

```bash
npm install @anthropic-ai/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 the Anthropic client to the Respan gateway">

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

```python
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url="https://gateway.respan.ai",
)

message = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Say hello in three languages."}],
)
print(message.content[0].text)
```

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

```typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.RESPAN_API_KEY,
  baseURL: "https://gateway.respan.ai",
});

const message = await client.messages.create({
  model: "claude-sonnet-4-5-20250929",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Say hello in three languages." }],
});
console.log(message.content[0].type === "text" ? message.content[0].text : "");
```

</Tab>
</Tabs>

</Step>
</Steps>

## Switch models

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

```python
message = client.messages.create(model="claude-sonnet-4-5-20250929", max_tokens=1024, messages=messages)
message = client.messages.create(model="claude-haiku-4-5-20251001", max_tokens=1024, messages=messages)
message = client.messages.create(model="claude-opus-4-5-20251101", max_tokens=1024, messages=messages)
```

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

## Respan parameters

Pass additional Respan parameters via `metadata` under the `respan_params` key for gateway features.

```python
message = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
    metadata={
        "respan_params": {
            "customer_identifier": "user_123",
            "metadata": {"session_id": "abc123"},
            "session_identifier": "conversation_456",
        }
    },
)
```

<Warning>
`respan_params` must be an **object**, as shown above. A string (including a `json.dumps` of the object), list, number or boolean is silently ignored: the request is still served, but no `customer_identifier` or other param applies. See [`respan_params` must be a JSON object](/docs/ai-gateway/customers/respan-params).
</Warning>

See [Respan params & metadata](/docs/ai-gateway/customers/respan-params) for the full list.
