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

# Anthropic Messages

> Use Messages authentication headers and native message formats.

## Basic call

Use `POST /v1/messages` with an `anthropic-messages` model. Supply `x-api-key`, `anthropic-version`, and an explicit `max_tokens` limit.

For the Python example, first run `python -m pip install anthropic`. The SDK Base URL is the gateway root without the final `/v1`.

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://YOUR-REGION.example/v1/messages" \
    -H "x-api-key: $CODEFLARE_API_KEY" \
    -H 'anthropic-version: 2023-06-01' \
    -H 'Content-Type: application/json' \
    -d '{"model":"MODEL_ID","max_tokens":256,"messages":[{"role":"user","content":"Hello"}]}'
  ```

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

  client = Anthropic(
      api_key=os.environ["CODEFLARE_API_KEY"],
      base_url="https://YOUR-REGION.example", max_retries=0,
  )
  with client.messages.stream(
      model="MODEL_ID", max_tokens=256,
      messages=[{"role": "user", "content": "Hello"}],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="", flush=True)
  ```
</CodeGroup>

## Streaming and tools

Set `stream: true` for native Messages events; the Anthropic SDK's `messages.stream` exposes text output. Tool calling and multimodal input require compatible models and channels. Do not parse OpenAI events as Messages events.

`POST /v1/messages/count_tokens` requires the channel's `count_tokens` capability. Token counting has no generation charge and does not guarantee admission of a subsequent request.

## Claude Code

See [Claude Code](/en/tools/claude-code) for client configuration. This endpoint does not expose Responses storage or HTTP continuation APIs. Check platform request logs after interruptions to avoid duplicate generation.


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