Anthropic SDK

Anthropic SDK setup for Python and TypeScript — note the base_url has no /v1.

On this page

Python

bash
pip install anthropic
python
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.apione.ai",   # note: no /v1
    api_key=os.environ["APIONE_API_KEY"],
)

msg = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,                     # required in this protocol
    system="You are a rigorous code reviewer.",
    messages=[{"role": "user", "content": "Review the edge cases in this function"}],
)
print(msg.content[0].text)
print(msg.usage.input_tokens, msg.usage.output_tokens)

Streaming

python
with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain the CAP theorem"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

TypeScript

bash
npm i @anthropic-ai/sdk
javascript
import Anthropic from "@anthropic-ai/sdk";

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

const msg = await client.messages.create({
  model: "claude-opus-4-7",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Review the edge cases in this function" }],
});
console.log(msg.content[0].type === "text" ? msg.content[0].text : "");

Three easy mistakes

SymptomCause
404base_url set to https://api.apione.ai/v1, so the SDK appended /v1 twice
400 max_tokens is requiredmax_tokens is mandatory in this protocol
No text foundThe body is in content[], not choices
Tip

The Anthropic SDK can call other vendors too — model="gpt-5.6-sol" works, and the gateway handles translation.

Contact us

Something unclear, or need a human? Pick the channel that fits your question.