Skip to main content

Use the Anthropic SDK

Proxium speaks the Anthropic Messages API at POST /v1/messages. A Messages call can go to any vendor of your project, not only Anthropic. Proxium translates the call and the answer.

SettingValue
Base URLhttps://proxium.tech, without /v1. The SDK adds /v1/messages
API keyA virtual key of your project, from Keys in the console
ModelA model id or a tier name of your project. Route requests to models explains both

Connect the client​

To connect, set the base URL and give your virtual key as the API key.

client.py
import os
from anthropic import Anthropic

client = Anthropic(
base_url="https://proxium.tech",
api_key=os.environ["PROXIUM_KEY"],
)

Send a message​

A request is a list of messages and a limit on the length of the reply. Give model and max_tokens: without one of them, Proxium answers 400.

message = client.messages.create(
model=os.environ["PROXIUM_MODEL"],
max_tokens=512,
system="You answer in one sentence.",
messages=[{"role": "user", "content": "What is a virtual key?"}],
)
print(message.content[0].text)

The answer has the Anthropic message shape:

FieldHolds
content[0].textThe reply
modelThe model that answered
usageThe token counts. Proxium prices the request from them

Stream the answer​

With streaming, the reply arrives in small pieces while the model writes it, so your app can show it as it grows. To stream, use the stream helper of the SDK, or set stream to true. Proxium sends the pieces as Anthropic server-sent events.

with client.messages.stream(
model=os.environ["PROXIUM_MODEL"],
max_tokens=512,
messages=[{"role": "user", "content": "Write a haiku about queues."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
print()

Check which fields reach the model​

Proxium passes onProxium drops
system, messages, tools, tool_choice, temperature, top_p, top_k, stop_sequences, stream, metadata.user_idcache_control, container, mcp_servers, service_tier
Text, image, tool_use and tool_result blocksthinking, redacted_thinking and document blocks
note

Proxium drops cache_control, so Anthropic prompt caching does not apply to a call through Proxium.

Handle errors​

An error comes in the Anthropic error shape, and the SDK raises the class for its status. A body that is too large is the one exception: it gets a 413 with a plain-text body.

Error body
{
"type": "error",
"error": {
"type": "authentication_error",
"message": "invalid or revoked key"
}
}
Statuserror.type
400, 415, 422invalid_request_error
401authentication_error
402, 403permission_error
404not_found_error
413request_too_large
429rate_limit_error
529overloaded_error
Any other statusapi_error

A 429 has a retry-after header with the seconds to wait. The message names the limit, for example source budget exceeded for 'support-bot' (calls). Errors lists each reason.

Next steps​