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

# POST /v1/messages — Anthropic Messages API

> Anthropic-compatible messages endpoint. Send requests using the Anthropic API format and authenticate with your TokModel key instead of an Anthropic key.

The `/v1/messages` endpoint is compatible with the Anthropic Messages API format, making it easy to migrate workloads from Anthropic's SDK or to use libraries that target Anthropic directly. You authenticate using your TokModel API key — you do not need an Anthropic API key. Route your Anthropic SDK to `https://tokmodel.com` and use your TokModel key to start using any model available on TokModel through the familiar Anthropic message format.

## Request parameters

<ParamField body="model" type="string" required>
  The ID of the model to use. You can use Anthropic model IDs (for example, `anthropic/claude-opus-4-5`) as well as any other model available on TokModel.
</ParamField>

<ParamField body="messages" type="array" required>
  An array of message objects representing the conversation. Each object requires a `role` (`"user"` or `"assistant"`) and a `content` field (a string or array of content blocks).
</ParamField>

<ParamField body="max_tokens" type="integer" required>
  The maximum number of tokens to generate. This parameter is required by the Anthropic format.
</ParamField>

<ParamField body="system" type="string">
  A system prompt that sets the context and instructions for the model. Equivalent to a `system` role message in other formats.
</ParamField>

<ParamField body="temperature" type="number" default="1">
  Sampling temperature between `0` and `1`. Lower values produce more consistent output.
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  When `true`, streams the response as server-sent events in Anthropic's streaming format.
</ParamField>

<ParamField body="top_p" type="number">
  Nucleus sampling threshold. Limits token selection to the smallest set whose cumulative probability exceeds `top_p`.
</ParamField>

<ParamField body="stop_sequences" type="string[]">
  An array of strings that cause the model to stop generating when encountered.
</ParamField>

## Response fields

<ResponseField name="id" type="string">
  A unique identifier for the message, prefixed with `msg_`.
</ResponseField>

<ResponseField name="type" type="string">
  Always `"message"`.
</ResponseField>

<ResponseField name="role" type="string">
  Always `"assistant"` for generated responses.
</ResponseField>

<ResponseField name="content" type="array">
  An array of content blocks in the response. Each block has a `type` field (typically `"text"`) and a `text` field with the generated content.
</ResponseField>

<ResponseField name="stop_reason" type="string">
  The reason generation stopped. One of `"end_turn"` (natural end), `"max_tokens"` (token limit reached), or `"stop_sequence"` (a stop sequence was matched).
</ResponseField>

<ResponseField name="model" type="string">
  The model that generated the response.
</ResponseField>

<ResponseField name="usage" type="object">
  Token counts for the request.

  <Expandable title="properties">
    <ResponseField name="input_tokens" type="integer">
      Number of tokens in the input messages and system prompt.
    </ResponseField>

    <ResponseField name="output_tokens" type="integer">
      Number of tokens in the generated response.
    </ResponseField>
  </Expandable>
</ResponseField>

## Example

<Note>
  Authenticate with your TokModel API key. You do not need an Anthropic API key to use this endpoint.
</Note>

### Request

```bash theme={null}
curl https://tokmodel.com/v1/messages \
  --request POST \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "anthropic/claude-opus-4-5",
    "system": "You are a concise technical writer.",
    "messages": [
      { "role": "user", "content": "What is a vector database?" }
    ],
    "max_tokens": 256,
    "temperature": 0.5
  }'
```

### Response

```json theme={null}
{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "A vector database stores and indexes high-dimensional numerical vectors, enabling fast similarity search. It is commonly used to power semantic search, recommendation systems, and retrieval-augmented generation (RAG) by finding the vectors closest to a given query vector."
    }
  ],
  "stop_reason": "end_turn",
  "model": "anthropic/claude-opus-4-5",
  "usage": {
    "input_tokens": 22,
    "output_tokens": 51
  }
}
```
