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//! - `lib`: Provider trait + implementations + conversion + types (for embedding
15//! the conversion logic in other Rust applications)
16//! - `server` (default): Full Pingora-based proxy binary (implies `lib`, adds
17//! config parsing, the HTTP server, CLI, and logging)
18//! - `telemetry`: OpenTelemetry tracing/metrics exporters
19//!
20//! # Usage (as library)
21//!
22//! ```ignore
23//! use codex_convert_proxy::{
24//! response_to_chat, chat_to_response, chat_to_response_with_context,
25//! chat_chunk_to_response_events, event_to_sse,
26//! Provider, GLMProvider, create_provider,
27//! StreamState, ResponseRequestContext, ResponseStreamEvent,
28//! types::response_api::{ResponseRequest, InputItemOrString},
29//! util::parse_sse,
30//! };
31//! ```
32//!
33//! # Providers
34//!
35//! Each Chinese LLM provider may have slightly different API requirements.
36//! Use the appropriate provider when converting:
37//!
38//! - [`GLMProvider`] - For Zhipu AI GLM models
39//! - [`KimiProvider`] - For Moonshot AI Kimi models
40//! - [`DeepSeekProvider`] - For DeepSeek models
41//! - [`MiniMaxProvider`] - For MiniMax models
42
43// Core modules (always available)
44pub mod constants;
45pub mod error;
46pub mod stats;
47pub mod types;
48pub mod util;
49
50// Conversion modules (require the `lib` feature for the Provider trait)
51#[cfg(feature = "lib")]
52pub mod convert;
53
54// Re-export main types
55pub use error::{ConversionError, ProxyError};
56pub use types::*;
57
58// Re-export convert functions (requires the `lib` feature)
59#[cfg(feature = "lib")]
60pub use convert::{
61 chat_chunk_to_response_events, chat_to_response, chat_to_response_with_context,
62 event_to_sse, response_to_chat,
63};
64
65// Re-export streaming types for library consumers
66#[cfg(feature = "lib")]
67pub use convert::ResponseRequestContext;
68#[cfg(feature = "lib")]
69pub use convert::streaming::{ResponseStreamEvent, StreamState};
70
71// Re-export stats
72pub use stats::{RequestRecord, RequestStats, StatsSummary, TokenUsage};
73
74// Providers module (`lib` feature)
75#[cfg(feature = "lib")]
76pub mod providers;
77
78#[cfg(feature = "lib")]
79pub use providers::{create_provider, DeepSeekProvider, GLMProvider, KimiProvider, MiniMaxProvider, Provider};
80
81// Config module (`server` feature - parsing backend definitions)
82#[cfg(feature = "server")]
83pub mod config;
84
85#[cfg(feature = "server")]
86pub use config::{BackendConfig, BackendInfo, BackendRouter, ProxyConfig};
87
88// Server functionality (server feature - Pingora proxy)
89#[cfg(feature = "server")]
90pub mod proxy;
91
92#[cfg(feature = "server")]
93pub mod server;
94
95#[cfg(feature = "server")]
96pub use proxy::CodexProxy;
97
98// CLI binary support (full feature implies binary)
99#[cfg(feature = "server")]
100pub mod cli;
101
102#[cfg(feature = "server")]
103pub use cli::{Cli, Commands, StartArgs};
104
105// Logging (server/binary feature - requires tracing-subscriber and tracing-appender)
106#[cfg(feature = "server")]
107pub mod logger;
108
109// Telemetry (`telemetry` feature)
110#[cfg(feature = "telemetry")]
111pub mod telemetry;
112
113#[cfg(feature = "telemetry")]
114pub use telemetry::TelemetryConfig;