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

# Messages API (Anthropic-compatible)

> Point an Anthropic SDK at Mesh and reach every model in the catalog through /v1/messages.

`POST /v1/messages` implements Anthropic's Messages API shape. If your code already
speaks that format — through the Anthropic SDK or a hand-rolled client — you can
switch the base URL to Mesh and keep the rest of the integration unchanged.

<Info>
  The endpoint is **not restricted to Anthropic models**. Any model this gateway
  serves is reachable through it, so an existing Anthropic client can call an
  OpenAI, Google, or open-weight model without changing its request shape.
</Info>

For new code, [`/v1/chat/completions`](/docs/getting-started/quickstart) remains the
recommended entry point — it has the widest feature coverage.

## Authentication

Both header styles are accepted:

```
x-api-key: rsk_YOUR_KEY
```

```
Authorization: Bearer rsk_YOUR_KEY
```

The `x-api-key` form is what Anthropic's own SDKs send, which is why an unmodified
client works once the base URL is pointed at Mesh.

## Basic request

<Tabs>
  <Tab title="curl">
    ```bash theme={null}
    curl https://api.meshapi.ai/v1/messages \
      -H "x-api-key: rsk_YOUR_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "anthropic/claude-sonnet-4.6",
        "max_tokens": 1024,
        "messages": [
          {"role": "user", "content": "Explain retrieval-augmented generation in two sentences."}
        ]
      }'
    ```
  </Tab>

  <Tab title="Python (Anthropic SDK)">
    ```python theme={null}
    from anthropic import Anthropic

    client = Anthropic(
        api_key="rsk_YOUR_KEY",
        base_url="https://api.meshapi.ai",
    )

    message = client.messages.create(
        model="anthropic/claude-sonnet-4.6",
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "Explain retrieval-augmented generation in two sentences."}
        ],
    )
    print(message.content[0].text)
    ```
  </Tab>

  <Tab title="Node.js (Anthropic SDK)">
    ```typescript theme={null}
    import Anthropic from "@anthropic-ai/sdk";

    const client = new Anthropic({
      apiKey: "rsk_YOUR_KEY",
      baseURL: "https://api.meshapi.ai",
    });

    const message = await client.messages.create({
      model: "anthropic/claude-sonnet-4.6",
      max_tokens: 1024,
      messages: [
        { role: "user", content: "Explain retrieval-augmented generation in two sentences." },
      ],
    });
    console.log(message.content[0].text);
    ```
  </Tab>
</Tabs>

## Streaming

Set `stream: true` for Anthropic's SSE event sequence — `message_start`,
`content_block_start`, `content_block_delta`, `content_block_stop`,
`message_delta`, `message_stop`. Anthropic's SDKs consume it unchanged.

```python theme={null}
with client.messages.stream(
    model="anthropic/claude-sonnet-4.6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Count to five."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

<Note>
  Token counts arrive on `message_delta`, not `message_start`. Anthropic reports
  input tokens on the first frame; Mesh only knows them once the upstream response
  completes, so `message_start.usage` carries zeros and `message_delta.usage` carries
  the real figures. SDKs that accumulate usage across the stream end up with the
  correct totals.
</Note>

## Request fields

| Field                   | Required | Notes                                                                                                   |
| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------- |
| `model`                 | Yes      | Any model in the Mesh catalog, in `provider/model-name` form                                            |
| `max_tokens`            | Yes      | Maximum tokens to generate — required by the Anthropic shape                                            |
| `messages`              | Yes      | `user` / `assistant` turns. A `system` turn is also accepted and keeps its position in the conversation |
| `system`                | No       | System prompt, passed as a top-level field rather than a message                                        |
| `temperature`           | No       | Sampling temperature                                                                                    |
| `top_p`                 | No       | Nucleus sampling                                                                                        |
| `top_k`                 | No       | Accepted for compatibility, but **not forwarded** — no provider mapping today                           |
| `stop_sequences`        | No       | Strings that halt generation                                                                            |
| `stream`                | No       | `true` for SSE — see [Streaming](#streaming)                                                            |
| `thinking`              | No       | Accepted for compatibility, but **not forwarded** yet                                                   |
| `tools` / `tool_choice` | No       | Anthropic-shaped tool definitions — see [Tool Calling](/docs/capabilities/tool-calling)                 |
| `metadata`              | No       | `metadata.user_id` is recorded as the end-user identifier on the usage row. Not echoed back             |

## Which endpoint should I use?

| Use case                                              | Endpoint                                            |
| ----------------------------------------------------- | --------------------------------------------------- |
| New integration, widest feature coverage              | `/v1/chat/completions`                              |
| Existing Anthropic SDK code you don't want to rewrite | `/v1/messages`                                      |
| Claude Code                                           | [`/v1/messages`](/docs/capabilities/claude-code)    |
| Reasoning effort, hosted tools, background jobs       | [`/v1/responses`](/docs/capabilities/responses-api) |
| Streaming output                                      | either — both support SSE                           |

## Related

* [Claude Code](/docs/capabilities/claude-code) — point the CLI at Mesh
* [Tool Calling](/docs/capabilities/tool-calling) — the function-calling cycle
* [Responses API](/docs/capabilities/responses-api) — reasoning effort and hosted tools
* [Available Models](/docs/reference/models-list) — every model this endpoint can reach
