> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routor.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate from Anthropic SDK

> Switch from the Anthropic SDK to Routor's OpenAI-compatible format.

# Migrate from Anthropic SDK

If you are using Anthropic's SDK directly, switching to Routor takes two changes. You swap to the OpenAI-compatible SDK format, which Routor uses as its standard interface.

***

## Before and After

### Python (Anthropic SDK → Routor)

**Before:**

```python theme={null}
import anthropic

client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

message = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "explain closures in JavaScript"}]
)

print(message.content[0].text)
```

**After:**

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ROUTOR_API_KEY"],
    base_url="https://api.routor.ai/v1",
)

response = client.chat.completions.create(
    model="auto",
    max_tokens=1024,
    messages=[{"role": "user", "content": "explain closures in JavaScript"}]
)

print(response.choices[0].message.content)
```

### Node.js (Anthropic SDK → Routor)

**Before:**

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

const message = await client.messages.create({
  model:      "claude-opus-4-5",
  max_tokens: 1024,
  messages:   [{ role: "user", content: prompt }],
});

console.log(message.content[0].text);
```

**After:**

```typescript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey:  process.env.ROUTOR_API_KEY,
  baseURL: "https://api.routor.ai/v1",
});

const response = await client.chat.completions.create({
  model:      "auto",
  max_tokens: 1024,
  messages:   [{ role: "user", content: prompt }],
});

console.log(response.choices[0].message.content);
```

***

## Key Differences

The Anthropic SDK uses a different response format than the OpenAI SDK. The main changes when moving to Routor's OpenAI-compatible format:

| Anthropic SDK              | Routor (OpenAI format)                |
| -------------------------- | ------------------------------------- |
| `message.content[0].text`  | `response.choices[0].message.content` |
| `client.messages.create()` | `client.chat.completions.create()`    |
| `max_tokens` param         | `max_tokens` param (same)             |
| `claude-opus-4-5` as model | `"auto"` as model                     |

***

## If You Still Want Claude Specifically

Routor will route to Claude when the prompt complexity justifies it. If you always want Claude regardless of complexity, set a tier floor that maps to Claude models:

```python theme={null}
response = client.chat.completions.create(
    model="auto",
    messages=[...],
    extra_body={"routor_tier_floor": "STANDARD"}
)
```

Or create a [Routing Profile](../playground/create-profile.md) with a tier floor set permanently, so every request from that key uses at least STANDARD tier where Claude Sonnet is the primary model.

***

## System Prompts

Both SDKs support system prompts, just in different formats. In the OpenAI format used by Routor:

```python theme={null}
response = client.chat.completions.create(
    model="auto",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user",   "content": prompt}
    ]
)
```
