> For the complete documentation index, see [llms.txt](https://anyint.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anyint.gitbook.io/docs/api-reference/anthropic-compatible.md).

# anthropic compatible

Use this family when your application already speaks Anthropic's Messages API or when you need message-block semantics that are different from OpenAI chat completions.

## Published routes

| Route                                                                   | Purpose                                              |
| ----------------------------------------------------------------------- | ---------------------------------------------------- |
| `POST https://gateway.api.anyint.ai/anthropic/v1/messages`              | Create a Claude-style message response               |
| `POST https://gateway.api.anyint.ai/anthropic/v1/messages/count_tokens` | Count tokens for a message payload before sending it |

## Required headers

```http
x-api-key: <ANYINT_API_KEY>
anthropic-version: 2023-06-01
content-type: application/json
```

## When to use this family

* You want Anthropic-style `messages` and `content` blocks
* You want text-plus-image inputs inside the same message format
* You need token estimation before sending expensive prompts

## Messages route

Use `/messages` when you want Anthropic-style request bodies and response objects.

### Core request fields

| Field        | Type    | Notes                                    |
| ------------ | ------- | ---------------------------------------- |
| `model`      | string  | Claude-compatible model ID               |
| `max_tokens` | integer | Maximum output tokens                    |
| `messages`   | array   | Alternating `user` and `assistant` turns |

Each `messages[].content` value can be either:

* a plain string
* an array of content blocks such as `text` and `image`

### Text-only example

```bash
curl https://gateway.api.anyint.ai/anthropic/v1/messages \
  -H "x-api-key: $ANYINT_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 512,
    "messages": [
      {"role": "user", "content": "Summarize why API gateways matter."}
    ]
  }'
```

### Image input example

```bash
curl https://gateway.api.anyint.ai/anthropic/v1/messages \
  -H "x-api-key: $ANYINT_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 512,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/png",
              "data": "<BASE64_IMAGE_DATA>"
            }
          },
          {
            "type": "text",
            "text": "Describe what is in this image."
          }
        ]
      }
    ]
  }'
```

### Response shape

The response returns a message object with:

* `content[]`: generated text blocks
* `usage.input_tokens`
* `usage.output_tokens`
* `stop_reason`

## Token count route

Use `/messages/count_tokens` when you need token estimation before sending a real request.

```bash
curl https://gateway.api.anyint.ai/anthropic/v1/messages/count_tokens \
  -H "x-api-key: $ANYINT_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "messages": [
      {"role": "user", "content": "Count the tokens for this message."}
    ]
  }'
```

Typical use cases:

* budget checks before high-context requests
* UI previews that warn about large prompts
* batching or queueing systems that need admission control

## Common mistakes

* Omitting the required `anthropic-version` header
* Sending `Authorization: Bearer` instead of `x-api-key`
* Assuming `content` must always be a string even though image blocks are supported
* Treating `/messages/count_tokens` as a generation route

## Related pages

* [Models API](/docs/api-reference/models-api.md)
* [Images](/docs/models-and-modalities/images-input.md)
* [Errors and Limits](/docs/api-reference/errors-and-limits.md)
