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

# Anthropic Messages

> Use Prism models through the Anthropic Messages and token-counting formats.

Prism serves its public models through the Anthropic Messages wire format. The
same model IDs and API keys work across the OpenAI and Anthropic formats.

## Create a message

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
POST https://api.prisminference.com/v1/messages
```

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    apiKey: process.env.PRISM_API_KEY,
    baseURL: "https://api.prisminference.com",
  });

  const message = await client.messages.create({
    model: "prism-glm53",
    max_tokens: 1024,
    system: "You are a senior TypeScript engineer.",
    messages: [
      { role: "user", content: "Write a bounded concurrency helper." },
    ],
  });

  const text = message.content.findLast((block) => block.type === "text");
  console.log(text?.type === "text" ? text.text : "");
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import anthropic

  client = anthropic.Anthropic(
      api_key=os.environ["PRISM_API_KEY"],
      base_url="https://api.prisminference.com",
  )

  message = client.messages.create(
      model="prism-glm53",
      max_tokens=1024,
      system="You are a senior TypeScript engineer.",
      messages=[
          {"role": "user", "content": "Write a bounded concurrency helper."}
      ],
  )

  text_blocks = [block.text for block in message.content if block.type == "text"]
  print(text_blocks[-1] if text_blocks else "")
  ```

  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.prisminference.com/v1/messages" \
    -H "x-api-key: $PRISM_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "prism-glm53",
      "max_tokens": 1024,
      "system": "You are a senior TypeScript engineer.",
      "messages": [
        {"role": "user", "content": "Write a bounded concurrency helper."}
      ]
    }'
  ```
</CodeGroup>

### Body parameters

| Field            | Type               | Required | Description                                               |
| ---------------- | ------------------ | -------- | --------------------------------------------------------- |
| `model`          | string             | Yes      | A [Prism model ID](/models).                              |
| `max_tokens`     | integer            | Yes      | Maximum number of generated tokens.                       |
| `messages`       | array              | Yes      | Alternating `user` and `assistant` conversation messages. |
| `system`         | string or block\[] | No       | System instructions, supplied separately from `messages`. |
| `stream`         | boolean            | No       | Return Anthropic streaming events when `true`.            |
| `temperature`    | number             | No       | Sampling temperature.                                     |
| `top_p`          | number             | No       | Nucleus sampling probability.                             |
| `stop_sequences` | string\[]          | No       | Custom sequences that stop generation.                    |
| `tools`          | array              | No       | Anthropic tool definitions available to the model.        |
| `tool_choice`    | object             | No       | Control tool selection.                                   |
| `thinking`       | object             | No       | Enable extended thinking with a token budget.             |

<Warning>
  Put system instructions in the top-level `system` field. A message with
  `role: "system"` inside `messages` returns `400`.
</Warning>

Reasoning may produce `thinking` blocks before the final `text` block. Find the
text block by type instead of assuming `content[0]` contains the answer.

## Count tokens

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
POST https://api.prisminference.com/v1/messages/count_tokens
```

The token-counting endpoint accepts the input fields used to create a message
and returns the number of input tokens.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.prisminference.com/v1/messages/count_tokens" \
  -H "x-api-key: $PRISM_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "prism-glm53",
    "system": "You are a senior TypeScript engineer.",
    "messages": [
      {"role": "user", "content": "Review this pull request: ..."}
    ]
  }'
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "input_tokens": 1842
}
```

## Authentication

The Anthropic headers are:

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
x-api-key: YOUR_PRISM_API_KEY
anthropic-version: 2023-06-01
content-type: application/json
```

`Authorization: Bearer YOUR_PRISM_API_KEY` is also accepted.
