Docs menu

Anthropic SDK

Wire: Anthropic. Base URL: https://sator-api.princep.orgno /v1; the SDK appends /v1/messages. State: verified.

Install#

bash
pip install anthropic                 # Python
npm install @anthropic-ai/sdk         # TypeScript / JavaScript

Configure#

Pass the base URL and key to the client, or set the environment variables the SDK reads on its own. auth_token / authToken sends the key as Authorization: Bearer; api_key / apiKey sends it as x-api-key. Sator accepts both; auth_token is the natural fit for a key that is not an Anthropic one.

bash
export ANTHROPIC_BASE_URL=https://sator-api.princep.org
export ANTHROPIC_AUTH_TOKEN=sk-sator-v1-...

Python#

python
from anthropic import Anthropic

client = Anthropic(base_url="https://sator-api.princep.org", auth_token="sk-sator-v1-...")

message = client.messages.create(
    model="deepseek-v4-flash",
    max_tokens=256,
    messages=[{"role": "user", "content": "Say hi"}],
)
print(message.content[0].text)
print(message.usage)

Streaming:

python
with client.messages.stream(
    model="deepseek-v4-flash",
    max_tokens=256,
    messages=[{"role": "user", "content": "Count to five"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

TypeScript#

ts
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({ baseURL: 'https://sator-api.princep.org', authToken: process.env.SATOR_API_KEY });

const message = await client.messages.create({
  model: 'deepseek-v4-flash',
  max_tokens: 256,
  messages: [{ role: 'user', content: 'Say hi' }],
});
console.log(message.content, message.usage);

Streaming:

ts
const stream = client.messages.stream({
  model: 'deepseek-v4-flash',
  max_tokens: 256,
  messages: [{ role: 'user', content: 'Count to five' }],
});
stream.on('text', (text) => process.stdout.write(text));
await stream.finalMessage();

max_tokens is required on this wire — the SDK's types already insist on it.

Verify#

Either sample prints a short reply and a usage object with non-zero input_tokens and output_tokens. The request appears in your dashboard.

What works, what does not#

  • client.messages.create / .stream — yes, with tools, output_config structured output, images and documents (base64 or URL source), and system. See Tool calling.
  • anthropic-beta headers — forwarded as sent.
  • client.messages.count_tokens — yes, as an estimate: a deterministic characters-per-token count, never billed. See Messages.
  • The SDK's typed errors map from the status the way Anthropic documents (AuthenticationError for 401, RateLimitError for 429, and so on), and the SDK retries 429 and 5xx on its own. See Errors.

Troubleshooting#

  • 404 on every call — the base URL has a /v1 on it. Remove it; the SDK adds the path.
  • AuthenticationError — the key is wrong or revoked; check the dashboard.
  • max_tokens required — this wire needs it on every request; there is no default.