NewEco lane now on 91 models: the same model at a lower price

Currency

You always top up in euro. Other currencies are shown at today's ECB rate. ECB reference rates

Sign inGet started

Docsv1

Docs menuAnthropic SDK

Anthropic SDK

Use the official Anthropic SDK for Python or Node with Nexrouting through the Messages API at /v1/messages.

POST /v1/messages speaks the Anthropic Messages format. Point the Anthropic SDK at https://api.nexrouting.com, without /v1: the SDK adds /v1/messages itself. The SDK sends your key as x-api-key, which the gateway accepts.

Install

pip install anthropic

Send a message

import osfrom anthropic import Anthropic client = Anthropic(    base_url="https://api.nexrouting.com",    api_key=os.environ["NEXROUTING_API_KEY"],) message = client.messages.create(    model="anthropic/claude-sonnet-5.5",    max_tokens=1024,    messages=[{"role": "user", "content": "Hello"}],)print(message.content[0].text)

Or set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY in the environment; both SDKs read them.

Which models

Only models that list /v1/messages in their endpoints accept this format: the Anthropic models and a number of others. Check GET /v1/models. Any other model returns 400 unsupported_endpoint; use it through /v1/chat/completions instead.

Version and beta headers

The SDK sets anthropic-version; the gateway passes it on to the model provider, and uses 2023-06-01 when it is missing. anthropic-beta is passed on as well. Whether a beta feature works depends on the model.

Streaming

with client.messages.stream(    model="anthropic/claude-sonnet-5.5",    max_tokens=1024,    messages=[{"role": "user", "content": "Write a haiku about routing."}],) as stream:    for text in stream.text_stream:        print(text, end="")

Prompt caching

cache_control on your content blocks is passed to the model provider. Writing to the cache is billed at a multiple of the input rate (1.25× for 5 minutes, 2× for 1 hour). Reading from the cache is billed at the normal input rate for now. See Pricing & usage.

Errors

Errors on /v1/messages use the Anthropic shape ({"type": "error", "error": {...}}), so the SDK raises its usual exceptions, such as RateLimitError for 429. See Errors.

Not available

Token counting (/v1/messages/count_tokens) and Message Batches return 404 not_found. GET /v1/models returns the OpenAI-style list described in List models, which the Anthropic SDK's models.list() may not read correctly; call it directly instead.