# Anthropic Messages API

https://modelportal.ai/docs/anthropic-messages

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.

```python
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](/docs/reasoning), [Tool calling](/docs/tool-calling) and [Prompt caching](/docs/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](/docs/provider-routing). `metadata.user_id` serves as the session identifier for [session affinity](/docs/default-routing) 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](/docs/api-anthropic).
