Integrations

Anthropic SDK

Use the Anthropic SDKs with Sovereign by changing the base URL and the key.

Set it up

import anthropic

client = anthropic.Anthropic(base_url="https://sov.solibra.ai", api_key="sov_live_…")
message = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about invoices."}],
)
print(message.content[0].text)

The SDK's ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY environment variables work too.

Streaming

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain prompt caching in one paragraph."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Tools, images and caching

  • Tools work as in the Messages API. Requests with tools only go to models that support tool use.
  • Images only go to models that accept them.
  • Prompt caching: your cache_control markers are kept. If you set none, Sovereign turns on caching for Claude models. See Prompt caching.

Counting tokens

client.messages.count_tokens(...) works and returns an estimate. See Count tokens.