Files
anyllm-proxy/crates/translator
whit3rabbitandClaude Opus 4.6 b6277a8b86 feat: operator observability dashboard with error classification
- Admin UI: operator view with request volume, token usage, latency,
  cost charts, failure table, and request timeline
- Backend: add error_kind() method and infer_error_kind() for stable
  error classification (rate_limit, timeout, backend_error, client_error)
- Admin DB: error_kind column in request_log, observability aggregate
  queries (bucketed timeseries, failure breakdown, timeline)
- Gemini: improved streaming translation, thinking block support,
  grounding metadata passthrough
- Request timeout: configurable REQUEST_TIMEOUT_SECS with streaming
  watchdog
- Model pricing: MODEL_PRICING_FILE for external pricing overrides
- Degradation header: ANYLLM_DEGRADATION_WARNINGS env var control

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 19:12:03 -05:00
..

anyllm_translate

Pure, IO-free translation between Anthropic Messages API and OpenAI Chat Completions / Responses API formats. Also supports Google Gemini native API translation.

No HTTP clients, no async runtime, no network calls. Just fn(A) -> B transformations.

Quick Start

use anyllm_translate::{TranslationConfig, translate_request, translate_response};
use anyllm_translate::anthropic::MessageCreateRequest;

let config = TranslationConfig::builder()
    .model_map("haiku", "gpt-4o-mini")
    .model_map("sonnet", "gpt-4o")
    .model_map("opus", "gpt-4o")
    .build();

let req: MessageCreateRequest = serde_json::from_str(r#"{
    "model": "claude-sonnet-4-6",
    "max_tokens": 100,
    "messages": [{"role": "user", "content": "Hello"}]
}"#).unwrap();

let openai_req = translate_request(&req, &config).unwrap();
assert_eq!(openai_req.model, "gpt-4o");

// Send openai_req to OpenAI, get response, then:
// let anthropic_resp = translate_response(&openai_resp, &req.model);

Supported APIs

  • Anthropic Messages API (request/response types, streaming SSE events)
  • OpenAI Chat Completions API (request/response types, streaming chunks)
  • OpenAI Responses API (request/response types, streaming events)
  • Google Gemini native API (generateContent types, streaming)

Features

  • Default: Pure translation types and mapping functions
  • middleware: Adds an axum middleware layer that intercepts Anthropic-format requests, translates them, forwards to a configurable backend, and translates responses back
[dependencies]
anyllm_translate = "0.1"

# With middleware support:
anyllm_translate = { version = "0.1", features = ["middleware"] }

Modules

Module Description
anthropic Anthropic Messages API types (request, response, streaming, errors)
openai OpenAI Chat Completions and Responses API types
gemini Google Gemini native API types
mapping Stateless conversion functions between APIs
config Translation configuration (model mapping, lossy behavior)
translate Convenience wrappers combining config with mapping
middleware Axum middleware layer (requires middleware feature)

Translation Coverage

  • Text messages, multi-turn conversations
  • System prompts (Anthropic system to OpenAI developer role or Responses instructions)
  • Tool definitions, tool calls, tool results
  • Image and document content blocks (documents degrade to text notes)
  • Streaming SSE event translation (state machines for each backend)
  • Token usage mapping
  • Error type/status code translation
  • Extended thinking (stripped when targeting OpenAI)

This crate is part of anyllm-proxy, which also includes a standalone HTTP proxy server.