The native Claude Messages protocol is available through /messages and preserves native message, content block, tool use, and error semantics.
https://api.tokensmarket.ai/v1POST /messagesThe endpoint remains fixed. Use the parameter documentation on this page to replace the model ID and request data.
${base_url}/messagesProvide the native headers as well when using a Claude-compatible client.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
x-api-key | string | Yes | — | Claude-compatible API Key header. |
anthropic-version | string | Yes | 2023-06-01 | Claude protocol version header. |
Content-Type | string | Yes | application/json | Send the request body as JSON. |
max_tokens and messages are required; send all other fields only when supported by the model.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Claude or compatible model ID. |
max_tokens | integer | Yes | — | Maximum number of output tokens allowed for this generation. |
messages | array | Yes | — | Claude Messages Array of messages. |
system | string | array | No | — | System commands. |
tools / tool_choice | array | object | No | — | Tool definitions and selection strategy. |
thinking | object | No | — | Extended thinking configuration. |
output_config | object | No | — | Output format and limit configuration. |
cache_control | object | No | — | Prompt cache controls. |
context_management | object | No | — | Context management configuration. |
stream | boolean | No | — | Enable Claude native SSE. |
This endpoint supports routing and soft sticky Sessions. Session ID is limited to 256 characters and is read in this order: top-level session_id, extra_body.session_id, then X-Session-Id.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
extra_body.provider | object | No | — | Container for provider filters, ranges, sorting, and priority. Options / constraints: ignore, *_range, only, sort, order, allow_fallbacks. |
session_id | string | No | — | Top-level Session ID for consecutive conversations or tasks on the same model. Options / constraints: Maximum 256 characters. |
extra_body.session_id | string | No | — | Session ID used when top-level session_id is not provided. Options / constraints: Maximum 256 characters. |
X-Session-Id | string | No | — | Request header used when no Session ID is provided in the body. Options / constraints: Maximum 256 characters. |
extra_body.provider.allow_fallbacks | boolean | No | — | Defaults to false when only is non-empty; otherwise defaults to true. Options / constraints: true can relax only, ranges, sort, and order; it never relaxes ignore, permissions, endpoint capabilities, or channel availability. |
The following fields are HTTP response headers, not JSON, SSE event, or binary response body fields. They are not guaranteed when a network failure prevents the request from reaching the gateway.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
X-Client-Request-Id | string | No | — | Echoed when supplied by the caller; the gateway does not generate it automatically when omitted. |
X-Upstream-Request-Id | string | No | — | Usually used for gateway request tracing; it does not represent the provider's original request ID. |
The error body follows the selected protocol. HTTP 400 means invalid_request, HTTP 402 means insufficient available balance or quota, and HTTP 429 means rate limiting.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
error.code | string | No | — | Machine-readable error code defined by the protocol. |
error.message | string | No | — | Human-readable error description. |
Native Claude streaming ends with the message_stop event and does not append data: [DONE]. If the stream is interrupted, message_stop may not arrive.
The examples use placeholders. Replace them with a currently available model ID from the model details page, and keep your API Key in a server-side environment variable.
curl https://api.tokensmarket.ai/v1/messages \
-H "x-api-key: $TOKEN_MARKET_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"<MODEL_ID>","max_tokens":512,"messages":[{"role":"user","content":"Hello"}],"extra_body":{"session_id":"conversation-<UUID>","provider":{"sort":["latency"]}}}'