Anthropic Messages API

Updated

The Anthropic-compatible API lets Claude Code and the Anthropic SDKs connect without code changes, and it serves any text model in the catalog, not just Claude.

Connecting

  • Set the base URL to https://modelportal.ai without /v1; the SDK builds https://modelportal.ai/v1/messages itself.
  • Send the key in the x-api-key header, or as Authorization: Bearer.
  • The old addresses under /anthropic/* are retired and return 410 with a message pointing to the new path.
import anthropic

client = anthropic.Anthropic(base_url="https://modelportal.ai", api_key="YOUR_API_KEY")
message = client.messages.create(
    model="MODEL_ID",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)

Differences from the OpenAI format

  • max_tokens is required.
  • thinking, tool use and cache_control are supported according to each endpoint's declared capabilities; see Reasoning, Tool calling and Prompt caching.
  • Signed thinking blocks sent back during multi-turn tool use pin later requests to the endpoint that produced the signature.
  • Pass routing preferences in the X-ModelPortal-Provider-Preferences header; see Provider selection. metadata.user_id serves as the session identifier for session affinity and is removed before forwarding.
  • Error bodies are {"type": "error", "error": {"type", "message"}} with no machine-readable code; the x-should-retry response header tells you whether a retry is worthwhile.

Endpoints and fields are in the Anthropic-compatible API reference.