1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! # anyllm_translate
//!
//! Pure, IO-free translation between Anthropic Messages API and OpenAI Chat Completions API.
//!
//! # Quick start
//!
//! ```rust
//! 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
//!
//! - [`anthropic`] -- Anthropic Messages API types
//! - [`openai`] -- OpenAI Chat Completions and Responses API types
//! - [`mapping`] -- Stateless conversion functions between APIs
//! - [`config`] -- Translation configuration (model mapping, lossy behavior)
//! - [`translate`] -- Convenience wrappers combining config with mapping functions
/// Anthropic Messages API types (request, response, streaming events, errors).
/// Translation configuration: model mapping and lossy-translation behavior.
/// Error types for translation failures.
/// Gemini native generateContent API types (request, response).
/// Stateless conversion functions between Anthropic and OpenAI API formats.
/// HTTP middleware for request/response translation (requires `middleware` feature).
/// OpenAI Chat Completions and Responses API types.
/// Convenience wrappers combining config with mapping functions.
/// Shared utilities: ID generation, JSON helpers, secret redaction.
// Convenience re-exports
pub use ;
pub use TranslateError;
pub use ;
pub use AnthropicTranslationContext;
pub use ReverseStreamingTranslator;
pub use ;