SDKs · Anthropic SDK (Python and TypeScript)
Use the Anthropic SDK with open-source models hosted in the EU
inference.eu accepts the Anthropic Messages format as well as the OpenAI format. If your application is built on the official Anthropic SDK, you can keep that code, change the base URL and key, and run it on open-weight models processed in European data centres.
- 01API format: Anthropic Messages
- 02EU data centres
- 03Covered by one DPA
Set it up in a few minutes
- 1
Create an API key in your inference.eu account and store it as
INFERENCE_EU_API_KEY. - 2
Install the SDK with
pip install anthropicornpm install @anthropic-ai/sdk. - 3
Create the client with
base_url(Python) orbaseURL(TypeScript) set to the inference.eu host without the trailing/v1. - 4
Pass your key as
api_keyand replace the model name with an inference.eu model id such askimi-k3. - 5
Send a short
messages.createrequest to confirm the connection, then add streaming or tools.
import os
from anthropic import Anthropic
# The Anthropic SDK adds /v1/messages itself, so drop the trailing /v1.
client = Anthropic(
base_url="https://api.inference.eu/v1".removesuffix("/v1"),
api_key=os.environ["INFERENCE_EU_API_KEY"],
)
message = client.messages.create(
model="kimi-k3",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarise GDPR Article 28 in two sentences."}],
)
print(message.content[0].text)
# TypeScript:
# const client = new Anthropic({ baseURL: "https://api.inference.eu/v1".replace(/\/v1$/, ""), apiKey: process.env.INFERENCE_EU_API_KEY });Why use the Anthropic SDK with inference.eu
Many teams first built their applications on the Anthropic Messages API, with its content blocks, system prompt field and tool use format. Rewriting that code for another API takes time and introduces risk. Because inference.eu speaks the Messages format directly, you can move the same code to open-weight models without changing how you build requests or read responses.
The official SDKs keep handling retries, timeouts, streaming events and typed errors. Only the endpoint, the key and the model name change, which keeps the switch small and easy to review.
How the configuration works
The Anthropic SDK appends /v1/messages to the base URL itself. Set base_url to the inference.eu host without the trailing /v1; the snippet strips it with removesuffix. In TypeScript the option is called baseURL.
Pass your key as api_key. The SDK sends it in the x-api-key header, which inference.eu accepts. Both SDKs also read ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from the environment when you pass nothing, which helps with tools you cannot edit. In your own code, explicit arguments with INFERENCE_EU_API_KEY make the provider obvious and avoid sending the wrong key.
Which models to choose
Use the model id from inference.eu in the model field. kimi-k3 and glm-5.3 are good general choices for applications written against the Messages API: they handle long system prompts, multi-turn conversations and tool use well.
For code generation or agents that edit files, qwen3-coder-480b-a35b-instruct is a strong option. For fast classification, extraction or high-volume tasks, gpt-oss-120b keeps latency low. Since only the model string changes, you can run the same request against several models and compare the results on your own data.
Troubleshooting
A 404 error almost always means the base URL still ends in /v1, so the SDK calls /v1/v1/messages. Remove the suffix. A 401 AuthenticationError means the key is missing or wrong; check you are not reading an old ANTHROPIC_API_KEY.
"Model not found" means the model value is a Claude model name rather than an inference.eu id. max_tokens is required by the Messages API, so keep it in every request. Features specific to Claude, such as certain beta headers or server-side tools, may not apply to open-weight models; remove them if a request is rejected.
Keeping data in the EU
With the base URL set to inference.eu, every request your application sends through the SDK is processed in EU data centres. Prompts and completions are never used for training. We sign a data processing agreement under Article 28 GDPR, publish our subprocessor list and bill in euros.
The SDK only talks to the base URL you configure. Check that every client in your code uses it, including clients created by libraries that read ANTHROPIC_BASE_URL. Logging, tracing and evaluation services in your stack may also store prompts, so review where they keep their data.
Anthropic SDK (Python and TypeScript): common questions
The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.
Related
- OpenAI SDK (Python and JavaScript)Point the official OpenAI Python or JavaScript SDK at inference.eu with base_url and an API key, and call open-weight models processed in the EU.SDKs
- Claude CodePoint Claude Code at inference.eu with ANTHROPIC_BASE_URL and run it on open-weight models processed in EU data centres. No Anthropic account needed.Coding agents
- LiteLLMAdd inference.eu to the LiteLLM proxy or Python SDK with the openai/ prefix and route your team's requests to open-weight models processed in the EU.Gateways
Move your AI workloads to EU infrastructure
Tell us which models you use and roughly how much traffic you have. We reply within one working day with pricing and next steps.
- Reply within one working day
- Pricing for your volume
- DPA ready to sign