api_openai/
lib.rs

1// src/lib.rs
2//! This is a library for interacting with the `OpenAI` API.
3//! It provides a client for various `OpenAI` services, including
4//! assistants, chat, embeddings, files, fine-tuning, images, models,
5//! moderations, realtime, responses, and vector stores.
6//!
7//! # Governing Principle : "Thin Client, Rich API"
8//!
9//! This library follows the principle of **"Thin Client, Rich API"** - exposing all
10//! server-side functionality transparently while maintaining zero client-side intelligence
11//! or **automatic** behaviors.
12//!
13//! **Key Distinction**: The principle prohibits **automatic/implicit** behaviors but explicitly
14//! **allows and encourages** **explicit/configurable** enterprise reliability features.
15//!
16//! ## Core Principles
17//!
18//! - **API Transparency**: One-to-one mapping with `OpenAI` API endpoints
19//! - **Zero Automatic Behavior**: No implicit decision-making or magic thresholds
20//! - **Explicit Control**: Developer decides when, how, and why operations occur
21//! - **Information vs Action**: Clear separation between data retrieval and state changes
22//! - **Configurable Reliability**: Enterprise features available through explicit configuration
23//!
24//! ## Enterprise Reliability Features
25//!
26//! The following enterprise reliability features are **explicitly allowed** when implemented
27//! with explicit configuration and transparent operation:
28//!
29//! - **Configurable Retry Logic**: Exponential backoff with explicit configuration
30//! - **Circuit Breaker Pattern**: Failure threshold management with transparent state
31//! - **Rate Limiting**: Request throttling with explicit rate configuration
32//! - **Failover Support**: Multi-endpoint configuration and automatic switching
33//! - **Health Checks**: Periodic endpoint health verification and monitoring
34//!
35//! ## State Management Policy
36//!
37//! **✅ ALLOWED: Runtime-Stateful, Process-Stateless**
38//! - Connection pools, circuit breaker state, rate limiting buckets
39//! - Retry logic state, failover state, health check state
40//! - Runtime state that dies with the process
41//! - No persistent storage or cross-process state
42//!
43//! **❌ PROHIBITED: Process-Persistent State**
44//! - File storage, databases, configuration accumulation
45//! - State that survives process restarts
46//!
47//! **Implementation Requirements**:
48//! - Feature gating behind cargo features (`retry`, `circuit_breaker`, `rate_limiting`, `failover`, `health_checks`)
49//! - Explicit configuration required (no automatic enabling)
50//! - Transparent method naming (e.g., `execute_with_retries()`, `execute_with_circuit_breaker()`)
51//! - Zero overhead when features disabled
52//!
53//! This design ensures predictable behavior, explicit control, and transparency
54//! for developers using the library.
55
56
57#[ cfg( feature = "enabled" ) ]
58use mod_interface::mod_interface;
59
60#[ cfg( feature = "enabled" ) ]
61mod private {}
62
63// Re-export ClientApiAccessors at crate root for convenience
64#[ cfg( feature = "enabled" ) ]
65pub use client_api_accessors::ClientApiAccessors;
66
67// Client extension modules (impl blocks for Client)
68#[ cfg( feature = "enabled" ) ]
69mod client_ext_builder;
70#[ cfg( feature = "enabled" ) ]
71mod client_ext_request_core;
72#[ cfg( feature = "enabled" ) ]
73mod client_ext_http_basic;
74#[ cfg( feature = "enabled" ) ]
75mod client_ext_http_stream;
76
77#[ cfg( feature = "enabled" ) ]
78crate ::mod_interface!
79{
80  // API endpoint modules
81  layer admin;
82  layer assistants;
83  #[ cfg( feature = "audio" ) ]
84  layer audio;
85  layer chat;
86  layer embeddings;
87  layer files;
88  layer fine_tuning;
89  layer images;
90  layer models;
91  #[ cfg( feature = "moderation" ) ]
92  layer moderations;
93  layer realtime;
94  layer responses;
95  layer uploads;
96  layer vector_stores;
97
98  // Core functionality modules
99  layer advanced_auth;
100  layer builder_enhancements;
101  layer client;
102  layer client_api_accessors;
103  layer components;
104  layer connection_manager;
105  // Temporarily disabled due to compilation errors
106  layer enhanced_batch_operations;
107  layer enhanced_client;
108  layer enhanced_client_builder;
109  layer enhanced_client_performance;
110  #[ cfg( feature = "batching" ) ]
111  layer enhanced_embeddings;
112  layer curl_generation;
113  layer diagnostics;
114  layer dynamic_configuration;
115
116  // Feature-gated enhanced modules
117  #[ cfg( feature = "circuit_breaker" ) ]
118  layer enhanced_circuit_breaker;
119  #[ cfg( feature = "rate_limiting" ) ]
120  layer enhanced_rate_limiting;
121  #[ cfg( feature = "retry" ) ]
122  layer enhanced_retry;
123  #[ cfg( feature = "enterprise" ) ]
124  layer enterprise;
125
126  layer environment;
127  layer error;
128
129  #[ cfg( feature = "failover" ) ]
130  layer failover;
131  #[ cfg( feature = "health_checks" ) ]
132  layer health_checks;
133
134  layer metrics_framework;
135  layer model_deployment;
136  layer model_tuning;
137
138  #[ cfg( feature = "model_comparison" ) ]
139  layer model_comparison;
140  #[ cfg( feature = "request_templates" ) ]
141  layer request_templates;
142  #[ cfg( feature = "buffered_streaming" ) ]
143  layer buffered_streaming;
144
145  #[ cfg( all( feature = "caching", feature = "compression" ) ) ]
146  layer performance_cache;
147
148  layer performance_monitoring;
149  layer platform_specific;
150
151  #[ cfg( feature = "input_validation" ) ]
152  layer input_validation;
153  #[ cfg( feature = "input_validation" ) ]
154  layer request_validation;
155
156  #[ cfg( feature = "batching" ) ]
157  layer request_batching;
158
159  layer request_cache;
160  layer request_cache_enhanced;
161
162  #[ cfg( feature = "caching" ) ]
163  layer response_cache;
164
165  layer secret;
166  #[ cfg( feature = "streaming_control" ) ]
167  layer streaming_control;
168  layer streaming_performance_enhanced;
169  layer sync;
170  layer websocket_reliability_enhanced;
171  layer websocket_streaming;
172
173  exposed use admin;
174  exposed use advanced_auth;
175  exposed use builder_enhancements;
176  exposed use client_api_accessors;
177  exposed use enhanced_batch_operations;
178  exposed use enhanced_client;
179  exposed use enhanced_client_builder;
180  exposed use enhanced_client_performance;
181  // Temporarily disabled due to compilation errors
182  #[ cfg( feature = "batching" ) ]
183  exposed use enhanced_embeddings;
184  exposed use components;
185  exposed use connection_manager;
186  exposed use curl_generation;
187  exposed use diagnostics;
188  exposed use dynamic_configuration;
189
190  // Feature-gated exposed modules
191  #[ cfg( feature = "circuit_breaker" ) ]
192  exposed use enhanced_circuit_breaker;
193  #[ cfg( feature = "rate_limiting" ) ]
194  exposed use enhanced_rate_limiting;
195  #[ cfg( feature = "retry" ) ]
196  exposed use enhanced_retry;
197  #[ cfg( feature = "enterprise" ) ]
198  exposed use enterprise;
199
200  exposed use environment;
201
202  #[ cfg( feature = "failover" ) ]
203  exposed use failover;
204  #[ cfg( feature = "health_checks" ) ]
205  exposed use health_checks;
206
207  exposed use metrics_framework;
208  exposed use model_deployment;
209  exposed use model_tuning;
210
211  #[ cfg( feature = "model_comparison" ) ]
212  exposed use model_comparison;
213  #[ cfg( feature = "request_templates" ) ]
214  exposed use request_templates;
215  #[ cfg( feature = "buffered_streaming" ) ]
216  exposed use buffered_streaming;
217
218  #[ cfg( all( feature = "caching", feature = "compression" ) ) ]
219  exposed use performance_cache;
220
221  exposed use performance_monitoring;
222  exposed use platform_specific;
223
224  #[ cfg( feature = "batching" ) ]
225  exposed use request_batching;
226
227  exposed use request_cache;
228  exposed use request_cache_enhanced;
229
230  #[ cfg( feature = "caching" ) ]
231  exposed use response_cache;
232
233  exposed use secret;
234  #[ cfg( feature = "streaming_control" ) ]
235  exposed use streaming_control;
236  exposed use streaming_performance_enhanced;
237  exposed use sync;
238  exposed use uploads;
239  exposed use websocket_reliability_enhanced;
240  exposed use websocket_streaming;
241  exposed use error;
242  exposed use client;
243}