Expand description
§anyllm_translate
Pure, IO-free translation between Anthropic Messages API and OpenAI Chat Completions API.
§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 ...
// let anthropic_resp = translate_response(&openai_resp, &req.model);§Modules
Re-exports§
pub use config::LossyBehavior;pub use config::TranslationConfig;pub use config::TranslationConfigBuilder;pub use error::TranslateError;pub use mapping::gemini_message_map::anthropic_to_gemini_response;pub use mapping::gemini_message_map::compute_gemini_request_warnings;pub use mapping::gemini_message_map::gemini_to_anthropic_request;pub use mapping::reverse_message_map::AnthropicTranslationContext;pub use mapping::reverse_streaming_map::ReverseStreamingTranslator;pub use translate::compute_request_warnings;pub use translate::new_gemini_stream_translator;pub use translate::new_responses_stream_translator;pub use translate::new_reverse_stream_translator;pub use translate::new_stream_translator;pub use translate::translate_anthropic_to_openai_response;pub use translate::translate_anthropic_to_openai_response_with_context;pub use translate::translate_openai_to_anthropic_request;pub use translate::translate_openai_to_anthropic_request_with_context;pub use translate::translate_request;pub use translate::translate_request_gemini;pub use translate::translate_request_responses;pub use translate::translate_response;pub use translate::translate_response_gemini;pub use translate::translate_response_responses;pub use translate::TranslationWarnings;
Modules§
- anthropic
- Anthropic Messages API types (request, response, streaming events, errors).
- config
- Translation configuration: model mapping and lossy-translation behavior.
- error
- Error types for translation failures.
- gemini
- Gemini native generateContent API types (request, response).
- mapping
- Stateless conversion functions between Anthropic and OpenAI API formats.
- openai
- OpenAI Chat Completions and Responses API types.
- translate
- Convenience wrappers combining config with mapping functions.
- util
- Shared utilities: ID generation, JSON helpers, secret redaction.