API

# Anthropic Messages

Anthropic Messages at `/v1/messages`. Anthropic SDKs take the bare origin `https://inference.dagon.so` as base URL (no `/v1`); errors on this endpoint use the Anthropic error shape.

**On this page**

- [Request](https://inference.dagon.so/docs/messages#request)
- [Forwarded fields](https://inference.dagon.so/docs/messages#forwarded-fields)
- [Count tokens](https://inference.dagon.so/docs/messages#count-tokens)

## Request

POST `/v1/messages`

**curl**

```curl
curl https://inference.dagon.so/v1/messages \
  -H "x-api-key: $DAGON_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "abliterated-model-large-flash", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'
```

**Python**

```python
# pip install anthropic
import os
import anthropic

client = anthropic.Anthropic(base_url="https://inference.dagon.so", api_key=os.environ["DAGON_KEY"])
msg = client.messages.create(
    model="abliterated-model-large-flash",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)
```

**TypeScript**

```ts
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ baseURL: "https://inference.dagon.so", apiKey: process.env.DAGON_KEY });
const msg = await client.messages.create({
  model: "abliterated-model-large-flash",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});
console.log(msg.content[0].type === "text" ? msg.content[0].text : msg.content);
```

## Forwarded fields

`model`, `messages`, `max_tokens`, `system`, `stop_sequences`, `stream`, `temperature`, `top_p`, `top_k`, `tools`, `tool_choice`, `thinking`, `metadata`. Anything else non-null is `400 unsupported_parameter`.

- `max_tokens` is required (`400 missing_max_tokens`), at most 65,536 or the model's limit.
- `tool_choice` may be `{type: "auto" | "any" | "none"}` or `{type: "tool", name}` naming one of the request's tools. Server tools (web search, web fetch, code execution, MCP) are refused.
- No `anthropic-beta` value is accepted: any beta is `400 unsupported_parameter`. `container`, `context_management`, `mcp_servers` and `file` sources are refused too.
- Images: `image` blocks with a `base64` source.

## Count tokens

POST `/v1/messages/count_tokens`

Free. Validated like `/v1/messages` and answered `{"input_tokens": n}`. It needs a key with credit available (`402 insufficient_credits` otherwise) and is limited to 600 calls per hour and 2 in flight per account. Counting is served by abliteration.ai, so a model it does not serve on Messages is `400 unsupported_endpoint`.

curl

```curl
curl https://inference.dagon.so/v1/messages/count_tokens \
  -H "x-api-key: $DAGON_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "abliterated-model-large-flash", "messages": [{"role": "user", "content": "Hello"}]}'
```

Last updated 2026-11-07

[Previous **Responses**](https://inference.dagon.so/docs/responses) [Next **Streaming**](https://inference.dagon.so/docs/streaming)
