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

# Messages

> The Anthropic Messages API shape, with the same automatic memory.

`POST /v1/messages` serves the Anthropic Messages shape over the same memory wrapper as
[Chat](/api-reference/chat), so an application built on the Anthropic SDK gets memory by
changing its base URL.

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

client = Anthropic(
    api_key="anona_live_YOUR_KEY",
    base_url="https://api.anonalabs.com",
    default_headers={"X-Anona-Space-Id": "support-bot"},
)

msg = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=512,
    messages=[{"role": "user", "content": "What plan am I on?"}],
)
print(msg.content[0].text)
```

The key can be sent as `x-api-key` (what the Anthropic SDK does) or as
`Authorization: Bearer`, the same Anona key either way.

<Note>
  The shape is a wire format, not a provider. `model` is a hint: the model that actually
  answers is the one this deployment serves, and you never supply a provider key.
</Note>

## Request

```bash theme={null}
POST https://api.anonalabs.com/v1/messages
x-api-key: anona_live_...
Content-Type: application/json
```

```json theme={null}
{
  "model": "claude-sonnet-4-6",
  "space_id": "support-bot",
  "max_tokens": 512,
  "system": "Answer in one sentence.",
  "messages": [
    { "role": "user", "content": "What plan am I on?" }
  ]
}
```

| Field         | Type            | Default            | Description                                                                                     |
| ------------- | --------------- | ------------------ | ----------------------------------------------------------------------------------------------- |
| `messages`    | array           | required           | Each `content` is a string or a list of typed blocks; text blocks are used, others are skipped. |
| `max_tokens`  | integer         | required           | Required by this API shape, and forwarded to the model.                                         |
| `system`      | string or array | none               | Becomes the system prompt. The memory block is prepended to it.                                 |
| `model`       | string          | deployment default | Optional.                                                                                       |
| `stream`      | boolean         | `false`            | Emit the Anthropic event stream.                                                                |
| `temperature` | float           | none               | Optional.                                                                                       |

All [memory tunables](/api-reference/chat#memory-tunables) apply here, in the body or as
`X-Anona-*` headers.

## Response

```json theme={null}
{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "content": [{ "type": "text", "text": "You're on the Scale plan." }],
  "model": "claude-sonnet-4-6",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": { "input_tokens": 42, "output_tokens": 9 },
  "memories_injected": 3,
  "space_id": "support-bot"
}
```

`memories_injected` and `space_id` are the Anona additions, and also arrive as the
`X-Anona-Memories-Injected` and `X-Anona-Space-Id` response headers.

## Streaming

`"stream": true` emits the Anthropic named-event sequence:

```
message_start
content_block_start
content_block_delta      ← one per token, {"type": "text_delta", "text": "..."}
content_block_stop
message_delta            ← stop_reason and output token count
message_stop
```

```python theme={null}
with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=512,
    messages=[{"role": "user", "content": "What plan am I on?"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

As on Chat, a failure before the first token is a normal JSON error with a real status
code; the turn is recorded and billed after the stream ends.
