Skip to content

Anthropic API Compatibility

TrustedRails API keys also work over the Anthropic Messages API. The same keys, models, and balance are served through both protocol surfaces: pick whichever your client speaks. Anthropic SDKs and Anthropic-native tools like Claude Code (see Connect Claude Code) work as drop-in clients.

https://proxy.trustedrails.com

Use the bare host as the base URL (for example in ANTHROPIC_BASE_URL or the Anthropic SDK's base_url); clients append the /v1/... paths themselves.

Both header styles are accepted:

  • x-api-key: tr-prx-... (the Anthropic SDK default)
  • Authorization: Bearer tr-prx-...

| Endpoint | Status | |---|---| | POST /v1/messages | Supported | | POST /v1/messages/count_tokens | Supported; returns an estimate (see below) | | GET /v1/models | Supported; Anthropic response shape when called with Anthropic headers |

| Parameter | Supported | |---|---| | model | Yes; a TrustedRails model id (see Supported Models) | | messages | Yes | | max_tokens | Yes (required, per the Anthropic spec) | | system | Yes | | stream | Yes | | temperature | Yes | | top_p | Yes | | top_k | Yes | | stop_sequences | Yes | | tools | Yes | | tool_choice | Yes: auto, none, and named tools. any is passed through but not strictly enforced by every model | | metadata | Accepted and ignored | | thinking | Yes: type toggles thinking on models with a thinking switch (no effect otherwise); budget_tokens accepted and ignored. See Supported Models | | cache_control | Accepted and ignored; no prompt caching |

Responses follow the Anthropic Messages format: content blocks, stop_reason, and a usage object with input_tokens and output_tokens. Streaming uses the Anthropic SSE event grammar (message_start → content block events → message_delta → message_stop).

Models that emit delimited thinking (MiniMax M2.7, GLM-5.3-Flash) return it as separate thinking content blocks in both streaming and non-streaming modes, so Anthropic clients render it natively. For DeepSeek V4 Flash the separation depends on the network serving configuration: deliberation may arrive as thinking blocks or inside the regular text blocks — don't rely on either shape for this model.

Tool use round-trips work end-to-end: the model returns tool_use blocks with parsed JSON input, and you send results back as tool_result blocks.

POST /v1/messages/count_tokens returns a documented estimate (derived from text length), not an exact tokenizer count. It is suitable for budgeting and context-window math, not for exact billing predictions; billing always uses the real token counts from the inference response.

  • Thinking defaults vary by model and can be inverted relative to Anthropic: MiniMax M2.7 and GLM-5.3-Flash think by default, so omitting thinking still returns thinking blocks — send thinking: {"type": "disabled"} to turn them off (on models with a switch). DeepSeek V4 Flash answers directly by default; send thinking: {"type": "enabled"} to make it deliberate. See reasoning behavior.
  • stop_sequences are honored, but stop_reason reports end_turn instead of stop_sequence: the network does not report which stop fired.
  • system-role messages inside the messages array are accepted (Claude Code sends them mid-conversation) and mapped to system messages; other unknown roles are rejected with 400.
  • Image and other non-text content blocks are not supported; text only.
  • Request bodies are limited to 2 MiB.

Errors use the Anthropic error shape, {"type": "error", "error": {"type": "...", "message": "..."}}:

| Status | Error type | |---|---| | 400 | invalid_request_error: validation errors, unsupported content, out-of-balance accounts | | 401 | authentication_error | | 404 | not_found_error: unknown endpoint or model | | 413 | request_too_large | | 429 | rate_limit_error: includes a Retry-After header |

  • Message Batches API (/v1/messages/batches)
  • Files API
  • Claude models: TrustedRails serves open-source models, and claude-* model ids are not aliased. Use the model ids from Supported Models.