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

# Anthropic SDK

> Use ModelStack with the Anthropic Python and TypeScript SDKs.

## Overview

While ModelStack uses an OpenAI-compatible API format, you can also use the Anthropic SDK by pointing it to ModelStack's API endpoint. This lets you use Anthropic-specific features while routing through ModelStack's unified billing and gateway.

<Note>
  We recommend using the [OpenAI SDK](/sdks/openai-sdk) for the best compatibility across all providers. The Anthropic SDK only works with Claude models.
</Note>

## Python

### Installation

```bash theme={null}
pip install anthropic
```

### Setup

```python theme={null}
import anthropic

client = anthropic.Anthropic(
    api_key="your_api_key",
    base_url="https://api.modelstack.cc"
)
```

### Chat Completion

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain quantum computing in simple terms."}
    ]
)

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

### Streaming

```python theme={null}
with client.messages.stream(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a poem about coding."}]
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

## TypeScript / Node.js

### Installation

```bash theme={null}
npm install @anthropic-ai/sdk
```

### Setup

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

const client = new Anthropic({
  apiKey: "your_api_key",
  baseURL: "https://api.modelstack.cc",
});
```

### Chat Completion

```typescript theme={null}
const message = await client.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 1024,
  messages: [
    { role: "user", content: "Explain quantum computing in simple terms." },
  ],
});

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

### Streaming

```typescript theme={null}
const stream = client.messages.stream({
  model: "claude-sonnet-4-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Write a poem about coding." }],
});

stream.on("text", (text) => {
  process.stdout.write(text);
});

await stream.finalMessage();
```

## When to Use the Anthropic SDK

Use the Anthropic SDK when you:

* Need Anthropic-specific features (tool use with Anthropic's format, prompt caching)
* Are only using Claude models
* Have existing Anthropic SDK code and want minimal changes

Use the [OpenAI SDK](/sdks/openai-sdk) when you:

* Want to switch between providers (Claude, GPT, Gemini) without changing SDKs
* Need a single SDK for all models
* Want maximum flexibility


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.