> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trylimitless.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic Messages

> Use the Messages protocol with your Limitless customer key.

`POST /v1/messages` accepts Anthropic-shaped messages and returns native JSON or SSE. Use a model ID from the Limitless catalog. This is protocol compatibility with our open-weight backend, not access to Anthropic-hosted Claude models.

The Anthropic SDK uses the API **origin**, without `/v1`. Set `LIMITLESS_API_ORIGIN` to `https://trylimitless.ai`, or `http://127.0.0.1:3001` locally. The OpenAI SDK uses an origin **with** `/v1`.

```python theme={null}
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["LIMITLESS_API_KEY"],
    base_url=os.environ["LIMITLESS_API_ORIGIN"],
    max_retries=0,
)

message = client.messages.create(
    model="abliterated-model",
    max_tokens=512,
    system="Answer briefly.",
    messages=[{"role": "user", "content": "Explain why a rainbow forms."}],
)
for block in message.content:
    if block.type == "text":
        print(block.text)
print(message.usage)
```

Install this example's dependency with `pip install anthropic`. `max_tokens`, `model`, and a non-empty `messages` array are required. System instructions belong in `system`.

## Stream content

Using the same client:

```python theme={null}
with client.messages.stream(
    model="abliterated-model",
    max_tokens=512,
    messages=[{"role": "user", "content": "Explain photosynthesis in two sentences."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    final_message = stream.get_final_message()
    print("\nUsage:", final_message.usage)
```

Raw clients should parse `message_start`, content-block events, `message_delta`, and `message_stop`. An `error` event or disconnect can end the stream before completion. The gateway records input/cache usage from the opening message and output totals from later usage events.

## Authentication and extensions

The SDK sends `x-api-key`. `Authorization: Bearer …` also works and takes precedence if both are present. The gateway forwards `anthropic-version` and `anthropic-beta`; it supplies version `2023-06-01` if omitted.

Custom tools use `name` and `input_schema`; return their results as `tool_result` blocks. Thinking, output schemas, images, and hosted web tools depend on model support. See [reasoning](/guides/reasoning), [images](/guides/images), and [web tools](/guides/web-tools).

Errors use the Messages envelope: `{ "type": "error", "error": { "type": "…", "code": "…", "message": "…" } }`. See [errors](/errors).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.