mirror of
https://github.com/whit3rabbit/anyllm-proxy.git
synced 2026-09-21 16:00:49 +00:00
Introduce `anyllm_client` crate containing HTTP client construction, SSRF-safe DNS resolver, retry/backoff logic, rate limit header parsing, and SSE frame parsing. These were previously inlined in the proxy crate. Rename crates from `anthropic_openai_proxy`/`anthropic_openai_translate` to `anyllm_proxy`/`anyllm_translate` throughout. proxy/backend: now re-exports retry, rate limit, and SSE symbols from the client crate; `send_with_retry` and `build_http_client` are thin adapters bridging BackendAuth/TlsConfig to the client crate's types. streaming: remove duplicate `find_double_newline` and `MAX_SSE_BUFFER_SIZE` definitions; import from `crate::backend` instead. Fix missing `pub mod` declarations in translator and proxy that were accidentally replaced by doc comments (streaming, usage_map, server, redact). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.2 KiB
Rust
66 lines
2.2 KiB
Rust
//! # anyllm_client
|
|
//!
|
|
//! Async HTTP client for Anthropic-to-OpenAI API translation.
|
|
//!
|
|
//! Accepts Anthropic Messages API requests, translates them to OpenAI Chat Completions
|
|
//! format, sends them to an OpenAI-compatible backend, and translates the response back.
|
|
//! Supports non-streaming and streaming (SSE) modes, retry with exponential backoff,
|
|
//! SSRF-safe DNS resolution, and mTLS.
|
|
//!
|
|
//! # Quick start
|
|
//!
|
|
//! ```rust,no_run
|
|
//! use anyllm_client::{Client, ClientConfig, Auth};
|
|
//! use anyllm_translate::TranslationConfig;
|
|
//! use anyllm_translate::anthropic::MessageCreateRequest;
|
|
//!
|
|
//! # async fn example() -> Result<(), anyllm_client::ClientError> {
|
|
//! let config = ClientConfig::builder()
|
|
//! .backend_url("https://api.openai.com/v1/chat/completions")
|
|
//! .auth(Auth::Bearer("sk-...".into()))
|
|
//! .translation(
|
|
//! TranslationConfig::builder()
|
|
//! .model_map("haiku", "gpt-4o-mini")
|
|
//! .model_map("sonnet", "gpt-4o")
|
|
//! .build()
|
|
//! )
|
|
//! .build();
|
|
//!
|
|
//! let client = Client::new(config);
|
|
//!
|
|
//! let req: MessageCreateRequest = serde_json::from_str(r#"{
|
|
//! "model": "claude-sonnet-4-6",
|
|
//! "max_tokens": 100,
|
|
//! "messages": [{"role": "user", "content": "Hello"}]
|
|
//! }"#).unwrap();
|
|
//!
|
|
//! let response = client.messages(&req).await?;
|
|
//! println!("{:?}", response);
|
|
//! # Ok(())
|
|
//! # }
|
|
//! ```
|
|
//!
|
|
//! # Modules
|
|
//!
|
|
//! - [`client`] -- High-level `Client` for Anthropic-in, Anthropic-out API calls
|
|
//! - [`http`] -- HTTP client builder with TLS and SSRF protection
|
|
//! - [`retry`] -- Generic retry logic with exponential backoff
|
|
//! - [`rate_limit`] -- Rate limit header extraction and format conversion
|
|
//! - [`sse`] -- Framework-agnostic SSE frame parser
|
|
//! - [`error`] -- Error types
|
|
|
|
pub mod client;
|
|
pub mod error;
|
|
pub mod http;
|
|
pub mod rate_limit;
|
|
pub mod retry;
|
|
pub mod sse;
|
|
|
|
// Convenience re-exports
|
|
pub use client::{Auth, Client, ClientConfig, ClientConfigBuilder};
|
|
pub use error::ClientError;
|
|
pub use http::{build_http_client, HttpClientConfig};
|
|
pub use rate_limit::RateLimitHeaders;
|
|
pub use retry::{backoff_delay, is_retryable, parse_retry_after, send_with_retry, RetryableError};
|
|
pub use sse::{find_double_newline, SseError};
|