Anthropic SDK integration
The official Anthropic SDKs work with Modellane through the Messages API (POST /v1/messages). Change the base URL and the key, and use a Modellane model id instead of a Claude model name.
Install#
Python
pip install anthropicNode.js
npm install @anthropic-ai/sdkConfigure the client#
The base URL is https://usemodellane.com, without /v1: the SDKs add /v1/messages themselves.
Python
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["MODELLANE_API_KEY"],
base_url="https://usemodellane.com",
)
message = client.messages.create(
model="deepseek-v4.1-flash",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
print(message.content[0].text)Node.js
import Anthropic from "@anthropic-ai/sdk"
const client = new Anthropic({
apiKey: process.env.MODELLANE_API_KEY,
baseURL: "https://usemodellane.com",
})
const message = await client.messages.create({
model: "deepseek-v4.1-flash",
max_tokens: 1024,
messages: [{ role: "user", content: "Write a haiku about the sea." }],
})
console.log(message.content[0].text)The key is sent in the x-api-key header, as the SDKs always do. A bearer token in Authorization works as well.
Streaming#
Python
with client.messages.stream(
model="deepseek-v4.1-flash",
max_tokens=1024,
messages=[{"role": "user", "content": "Count to five."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Node.js
const stream = client.messages.stream({
model: "deepseek-v4.1-flash",
max_tokens: 1024,
messages: [{ role: "user", content: "Count to five." }],
})
stream.on("text", (text) => process.stdout.write(text))
await stream.finalMessage()Count tokens#
client.messages.count_tokens (Python) and client.messages.countTokens (TypeScript) call POST /v1/messages/count_tokens. The count is a free estimate from the prompt size and can differ from the prompt tokens you are billed for.
Verify#
Run the first example. A printed reply means the base URL, key and model id are right. The SDK raises an authentication error for a wrong key and a not found error for a model id that is not in Models & pricing.
What is different#
- Model ids: Claude model names are not mapped; use ids from Models & pricing.
- Thinking: with
thinkingturned on, the model's reasoning comes back asthinkingblocks with an empty signature, butbudget_tokensis not applied. - Tools: your own tools work with
tool_useandtool_resultblocks. Server tools such as web search and code execution are ignored. - Not available: the Files API, Message Batches,
documentblocks and image URLs.
The Anthropic Messages API guide covers every mapping and limit, and Messages lists the fields.