La documentation est disponible en anglais.

Documentation / Anthropic-compatible

Create a message

POST/anthropic/v1/messages

Anthropic Messages API shape, converted to the TokenSaver pipeline and remapped back to an Anthropic message (or SSE when stream: true). max_tokens is required, as in the Anthropic contract.

Request highlights

  • model — prefer provider/model_id (e.g. anthropic/claude-sonnet-4-6) from GET /anthropic/v1/models; omit to use the key’s default_model
  • messages — user / assistant; content is a string or a list of blocks (text, tool_use, tool_result). Inline system / developer turns (sent by Claude Code) are hoisted to the top-level system field
  • system — string or list of text blocks → merged into pipeline instructions
  • max_tokens — required; Free plan output cap may apply
  • stream: true — Anthropic SSE events; see Tools & streaming
  • tools, tool_choice — function calling (plan quotas may apply); top_p, top_k, metadata are accepted and ignored (phase 1)

Minimal curl

curl -sS "https://api.tokensaver.fr/anthropic/v1/messages" \
  -H "x-api-key: $TS_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-6",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Anthropic Python SDK

from anthropic import Anthropic

client = Anthropic(
    api_key="ts_...",  # TokenSaver key, not the vendor key
    base_url="https://api.tokensaver.fr/anthropic",
)
msg = client.messages.create(
    model="anthropic/claude-sonnet-4-6",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)

Response (non-stream)

Standard Anthropic message envelope. content is a text block followed, if any, by one or more tool_use blocks. stop_reason is one of end_turn, tool_use, max_tokens, stop_sequence.

{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "model": "anthropic/claude-sonnet-4-6",
  "content": [{ "type": "text", "text": "Hello! How can I help?" }],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": { "input_tokens": 12, "output_tokens": 34 }
}

Content blocks (agent loop)

  • text → message text
  • tool_use (assistant) → internal tool calls (id → tool_call id, input object → JSON arguments)
  • tool_result (user) → one role: tool message per result (tool_use_id → tool_call_id)
  • image / thinking blocks: not supported in phase 1 (ignored)