Client APIs

anthropic_messages_to_chat_completions

Transforms Anthropic Messages API requests to Chat Completions-compatible request bodies and transforms compatible responses back.

Praxis AI v0.12.1 (alpha) 3 min read
On this page

Transforms Anthropic Messages API requests to Chat Completions-compatible request bodies and transforms compatible responses back. The name refers to the Chat Completions wire shape, not the OpenAI Responses API; any Chat Completions-compatible backend is a valid target, not only OpenAI.

Configuration Notes

Request fields the translation does not map are forwarded untouched for the backend to validate. Fields whose effect the translated response could not report truthfully (service_tier, container, inference_geo, mcp_servers, and Chat Completions fields such as n or logprobs whose output the translated response would discard) are rejected with a 400. Unsupported semantic content is rejected because Chat Completions cannot represent it faithfully.

allow_lossy_features opts specific Anthropic-only features into operator-approved degradation instead of that 400. Each listed feature is validated and then degraded as the feature requires — most have their wire markers stripped, while mid_conversation_system folds mid-conversation system messages into the leading system message — so an unmodified client (for example Claude Code, which always sends cache_control and thinking) can still drive a Chat Completions backend. Each degradation is reported to the operator — one WARN log per request, a praxis_anthropic_messages_to_chat_completions_degraded_total counter per feature, and an x-degraded-features response header — because the request succeeds but the feature was silently dropped. prompt_caching removes cache_control markers (prompt and tool content are preserved, but explicit cache breakpoints are not honored, so cost and latency may differ); extended_thinking removes thinking and thinking-only context_management edits (the translated response carries no thinking blocks); mid_conversation_system folds each eligible text-only system message with exactly role and content fields that appears after the first non-system turn into the single leading system message; other message or content shapes remain subject to strict validation and can be rejected with a 400. Features absent from the allowlist, malformed markers, and other context_management edits are still rejected with a 400 — except that without mid_conversation_system the translator does not reject in-array system messages itself: it preserves them in their original positions (Chat Completions represents them directly) and the backend decides whether to accept that ordering.

Translation ends the Anthropic wire contract, so the filter removes anthropic-version and both Anthropic credential forms (x-api-key from SDK v1 and authorization: Bearer from SDK v2) before the request reaches the Chat Completions backend. Use credential_injection to add the backend’s own token. The caller’s API version does not change translation: temperature, top_p, and top_k are forwarded under either version, and document blocks and non-empty citations are rejected under either version.

Configuration

FieldTypeRequiredDescription
allow_lossy_features(extended_thinking | prompt_caching | mid_conversation_system)[]noAnthropic features the operator allows the translator to degrade. Empty by default, which keeps the strict reject behavior for every feature. Unknown names fail config loading (deny_unknown_fields plus the validated LossyFeature enum), so a typo cannot silently widen what the translator will drop.
max_body_bytesintegernoMaximum body size in bytes for StreamBuffer mode.

Examples

Example 1

filter: anthropic_messages_to_chat_completions

Example 2

filter: anthropic_messages_to_chat_completions
max_body_bytes: 1048576
allow_lossy_features:
  - prompt_caching
  - extended_thinking