Skip to main content

codex_convert_proxy/
lib.rs

1//! Codex Convert Proxy Library
2//!
3//! A library for converting between OpenAI Responses API (used by Codex)
4//! and Chat Completions API (used by Chinese LLM providers).
5//!
6//! # Overview
7//!
8//! Codex 0.118+ only supports the Responses API, but Chinese LLM providers
9//! (GLM, Kimi, DeepSeek, MiniMax) only support the Chat Completions API.
10//! This library provides bidirectional conversion between these formats.
11//!
12//! # Features
13//!
14//! - `providers-lib`: Provider trait + implementations + conversion functions (minimal embedding)
15//! - `config-lib`: BackendRouter and config types (optional, for standalone proxy)
16//! - `lib`: Alias for `providers-lib`
17//! - `full` (default): Full library including server functionality and CLI
18//! - `server`: Pingora-based proxy server (implies `lib` + `config-lib`)
19//! - `binary`: CLI binary support (alias for `full`)
20//!
21//! # Usage (as library)
22//!
23//! ```ignore
24//! use codex_convert_proxy::{
25//!     response_to_chat, chat_to_response, chat_to_response_with_context,
26//!     chat_chunk_to_response_events, event_to_sse,
27//!     Provider, GLMProvider, create_provider,
28//!     StreamState, ResponseRequestContext, ResponseStreamEvent,
29//!     types::response_api::{ResponseRequest, InputItemOrString},
30//!     util::parse_sse,
31//! };
32//! ```
33//!
34//! # Providers
35//!
36//! Each Chinese LLM provider may have slightly different API requirements.
37//! Use the appropriate provider when converting:
38//!
39//! - [`GLMProvider`] - For Zhipu AI GLM models
40//! - [`KimiProvider`] - For Moonshot AI Kimi models
41//! - [`DeepSeekProvider`] - For DeepSeek models
42//! - [`MiniMaxProvider`] - For MiniMax models
43
44// Core modules (always available)
45pub mod constants;
46pub mod error;
47pub mod stats;
48pub mod types;
49pub mod util;
50
51// Conversion modules (require providers-lib for Provider trait)
52#[cfg(feature = "providers-lib")]
53pub mod convert;
54
55// Re-export main types
56pub use error::{ConversionError, ProxyError};
57pub use types::*;
58
59// Re-export convert functions (requires providers-lib)
60#[cfg(feature = "providers-lib")]
61pub use convert::{
62    chat_chunk_to_response_events, chat_to_response, chat_to_response_with_context,
63    event_to_sse, response_to_chat,
64};
65
66// Re-export streaming types for library consumers
67#[cfg(feature = "providers-lib")]
68pub use convert::streaming::{ResponseRequestContext, ResponseStreamEvent, StreamState};
69
70// Re-export stats
71pub use stats::{RequestRecord, RequestStats, StatsSummary, TokenUsage};
72
73// Providers module (providers-lib feature)
74#[cfg(feature = "providers-lib")]
75pub mod providers;
76
77#[cfg(feature = "providers-lib")]
78pub use providers::{create_provider, DeepSeekProvider, GLMProvider, KimiProvider, MiniMaxProvider, Provider};
79
80// Config module (config-lib feature - optional for standalone proxy)
81#[cfg(feature = "config-lib")]
82pub mod config;
83
84#[cfg(feature = "config-lib")]
85pub use config::{BackendConfig, BackendInfo, BackendRouter, ProxyConfig};
86
87// Server functionality (server feature - Pingora proxy)
88#[cfg(feature = "server")]
89pub mod proxy;
90
91#[cfg(feature = "server")]
92pub mod server;
93
94#[cfg(feature = "server")]
95pub use proxy::CodexProxy;
96
97// CLI binary support (full feature implies binary)
98#[cfg(feature = "full")]
99pub mod cli;
100
101#[cfg(feature = "full")]
102pub use cli::{Cli, Commands, StartArgs};
103
104// Logging (server/binary feature - requires tracing-subscriber and tracing-appender)
105#[cfg(feature = "server")]
106pub mod logger;
107
108// Telemetry (telemetry-lib feature)
109#[cfg(feature = "telemetry-lib")]
110pub mod telemetry;
111
112#[cfg(feature = "telemetry-lib")]
113pub use telemetry::TelemetryConfig;