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

# Anthropic SDK (gateway)

> 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` required.

## Setup

#### Install packages

**`Python`**

```bash Python
pip install anthropic
```

**`TypeScript`**

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

**`Python`**

```python Python
import os
from anthropic import Anthropic

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

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

**`TypeScript`**

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

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

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 : "");
```

## 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"},
            "thread_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/documentation/features/gateway/respan-params#respan_params-must-be-a-json-object).

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