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

# Messages

> Send text conversations in the Anthropic Messages format.

Use the same derestricted key and account balance as the OpenAI-compatible endpoints.

<ParamField header="x-api-key" type="string" required>
  Your derestricted API key. `Authorization: Bearer ...` is also accepted.
</ParamField>

<ParamField header="anthropic-version" type="string" default="2023-06-01">
  Sent by Anthropic SDKs. Use the SDK's normal version header; it does not
  enable provider-specific features.
</ParamField>

<ParamField body="model" type="string" default="derestricted-llm">
  Use `derestricted-llm`.
</ParamField>

<ParamField body="messages" type="array" required>
  User and assistant turns. Text content can be a string or text blocks. Include
  the history needed for the current turn. Maximum 2,000 items.
</ParamField>

<ParamField body="system" type="string or array">
  Optional top-level system instructions. Do not put a `system` role inside the
  Messages conversation array.
</ParamField>

<ParamField body="max_tokens" type="integer">
  Set an output allowance; Anthropic SDKs require this argument. The service
  caps it at 65,536 and checks that available credit can cover the reservation.
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Set to `true` for Messages-style server-sent events.
</ParamField>

<ParamField body="tools" type="array">
  Optional tools defined with `name`, `description`, and `input_schema`. Your
  application executes requested tools and supplies their `tool_result` content
  in a later request.
</ParamField>

## Example

```bash theme={"system"}
curl https://api.derestricted.ai/v1/messages \
  -H "x-api-key: $DERESTRICTED_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "derestricted-llm",
    "max_tokens": 8192,
    "system": "Answer concisely.",
    "messages": [{"role": "user", "content": "Explain how a circuit breaker helps a service recover."}]
  }'
```

Read text from entries in `content` whose `type` is `text`. A message can also contain reasoning or tool-use blocks. Check `stop_reason` and the `usage` fields; reaching `max_tokens` can produce an incomplete answer.

## Streaming

```python theme={"system"}
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.derestricted.ai",
    api_key=os.environ["DERESTRICTED_API_KEY"],
)

with client.messages.stream(
    model="derestricted-llm",
    max_tokens=8192,
    messages=[{"role": "user", "content": "Explain how a circuit breaker helps a service recover."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

Raw clients receive events such as `message_start`, `content_block_start`, `content_block_delta`, `message_delta`, and `message_stop`. `ping` events are keepalives. An `error` event can arrive after an HTTP `200`; do not interpret it as a normal completion.

The `thinking`, `output_config`, `mcp_servers`, `container`, and other [provider-specific controls](/api/anthropic-compatibility#compatibility-boundaries) do not configure this model. See [count tokens](/api/count-tokens) for the separate approximate input estimator.
