Skip to content

4 Uncensored LLM model added, currently available for only pay-as-you-go users.See Models

Messages (Anthropic API)

Call POST /v1/messages with Anthropic SDKs or curl: base URL, headers, a full example, streaming events, error shapes, and which headers are not forwarded.

Last updated 17 Nov 2026

On this page

Tokens serves the Anthropic Messages API at POST https://tokens.bd/v1/messages. This is the endpoint Claude Code and the Anthropic SDKs call, so you can point them at Tokens by changing the base URL and key. You can request any model in your catalog through it, not only Claude models.

Base URL and headers#

Anthropic SDKs and Claude Code add /v1/messages themselves, so their base URL is the bare host: https://tokens.bd.

HeaderValueRequired
x-api-key or Authorizationtok_live_your_key or Bearer tok_live_your_keyYes
anthropic-version2023-06-01Recommended; forwarded upstream
anthropic-betaBeta flags, comma separatedOptional; forwarded upstream
content-typeapplication/jsonYes

The SDKs send x-api-key and anthropic-version for you. Claude Code with ANTHROPIC_AUTH_TOKEN sends a Bearer header instead; both work.

Send a Messages API request with curl#

bash
curl https://tokens.bd/v1/messages \
  -H "x-api-key: $TOKENS_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "deepseek/deepseek-v4.1-flash",
    "max_tokens": 512,
    "system": "You are a concise senior engineer.",
    "messages": [
      {"role": "user", "content": "Explain idempotency keys in two sentences."}
    ]
  }'

max_tokens is required by the Messages API. A typical response:

json
{
  "id": "msg_01AbCdEf",
  "type": "message",
  "role": "assistant",
  "model": "deepseek/deepseek-v4.1-flash",
  "content": [
    { "type": "text", "text": "An idempotency key is a client-chosen id sent with a request..." }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": { "input_tokens": 31, "output_tokens": 58 }
}

Use the Anthropic Python SDK#

python
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://tokens.bd",
    api_key=os.environ["TOKENS_API_KEY"],
)

message = client.messages.create(
    model="deepseek/deepseek-v4.1-flash",
    max_tokens=512,
    messages=[{"role": "user", "content": "Explain idempotency keys in two sentences."}],
)
print(message.content[0].text)
print(message.usage)

The TypeScript SDK works the same way: new Anthropic({ baseURL: "https://tokens.bd", apiKey: process.env.TOKENS_API_KEY }).

For Claude Code, the settings live in ~/.claude/settings.json; see the setup steps in the quickstart or the snippet at Connect your agent.

Native and translated models on /v1/messages#

Each model is served by one or more upstream providers. When a provider speaks the Messages API, your request goes to it as is: thinking blocks, prompt caching, anthropic-beta features and the exact usage numbers come back untouched. Tokens prefers such a provider whenever one serves the model.

When the model is only available from a provider that speaks the OpenAI format, the gateway translates your Messages request into a chat completions request and translates the answer back. system, messages (text and images), max_tokens, stop_sequences, temperature, top_p, tools and tool_choice are carried across. Anthropic-only content (prompt caching markers, extended thinking blocks, documents) may be dropped in translation, so test those features against the specific model before depending on them.

Sampling parameters on newer Claude models#

Some Claude models no longer accept temperature (and none of the current ones accept temperature together with top_p). When the model refuses one of these, Tokens sends the request again without it, so tools that always set a temperature keep working. The model then uses its default sampling. The same applies when you call a Claude model through /v1/chat/completions.

Streaming events#

Set "stream": true and the response is Server-Sent Events in Anthropic's format:

text
event: message_start
data: {"type":"message_start","message":{"id":"msg_01AbCdEf","type":"message","role":"assistant","content":[],"model":"deepseek/deepseek-v4.1-flash","stop_reason":null,"usage":{"input_tokens":31,"output_tokens":0}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"An idempotency"}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":58}}

event: message_stop
data: {"type":"message_stop"}

Tool calls stream as a content_block_start with "type": "tool_use" followed by input_json_delta deltas. With the Python SDK, client.messages.stream(...) handles the event parsing. More on disconnects and timeouts in streaming.

Error shapes on /v1/messages#

Every error on /v1/messages and /v1/messages/count_tokens uses Anthropic's error format, whether it came from Tokens (bad key, no balance, plan limits) or from the upstream provider:

json
{
  "type": "error",
  "error": {
    "type": "billing_error",
    "message": "Prepaid wallet balance is insufficient for this request. Top up your wallet in the dashboard: https://tokens.bd/dashboard/billing",
    "code": "insufficient_credits"
  },
  "request_id": "8f0c7a4e-2b1d-4c55-9a51-3f7e2d9b6c10"
}

error.type follows Anthropic's list (invalid_request_error, authentication_error, billing_error, permission_error, not_found_error, request_too_large, rate_limit_error, api_error, overloaded_error), so the SDKs and Claude Code raise the right exception and retry where they should. Errors from Tokens also carry error.code, which tells you exactly which limit was hit; see errors.

Upstream error messages are replaced with a generic one so internal provider details don't leak. Read x-tokens-request-id from the response headers when you contact support.

Count tokens#

POST /v1/messages/count_tokens takes the same body as /v1/messages (without max_tokens) and returns {"input_tokens": N}. It is never billed and never runs the model, but it is not free of limits: it counts toward your per-minute request limit, takes a concurrency slot, and needs a funded account (a used-up usage window or a key's allowed-models list blocks it like any other request). See Token counting.

When a provider that serves the model counts tokens natively, you get its exact count. Otherwise Tokens answers with an estimate and adds the response header x-tokens-estimated: true. Use it for rough budgeting; the usage object in each response is what you are billed on.

anthropic-beta#

The anthropic-beta header is forwarded to providers that speak the Messages API, so beta features (newer tool types, extended context and so on) work where the provider supports them. On models served through translation the header has no effect.

List models in Anthropic format#

GET /v1/models answers in Anthropic's format when the request carries anthropic-version (the Anthropic SDKs send it), so client.models.list() works:

json
{
  "data": [
    {
      "type": "model",
      "id": "deepseek/deepseek-v4.1-flash",
      "display_name": "DeepSeek V4.1 Flash",
      "created_at": "2026-09-01T00:00:00.000Z"
    }
  ],
  "has_more": false,
  "first_id": "deepseek/deepseek-v4.1-flash",
  "last_id": "deepseek/deepseek-v4.1-flash"
}

Was this page helpful?

Still stuck? Open a support ticket

Need help configuring your agent?

Test your connection with the connection tester, or create an API key.