Skip to main content

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  #[ cfg( feature = "websocket" ) ]
94  layer realtime;
95  layer responses;
96  layer uploads;
97  layer vector_stores;
98
99  // Core functionality modules
100  layer advanced_auth;
101  layer builder_enhancements;
102  layer client;
103  layer client_api_accessors;
104  layer components;
105  layer connection_manager;
106  // Temporarily disabled due to compilation errors
107  layer enhanced_batch_operations;
108  layer enhanced_client;
109  layer enhanced_client_builder;
110  layer enhanced_client_performance;
111  #[ cfg( feature = "batching" ) ]
112  layer enhanced_embeddings;
113  layer curl_generation;
114  layer diagnostics;
115  layer dynamic_configuration;
116
117  // Feature-gated enhanced modules
118  #[ cfg( feature = "circuit_breaker" ) ]
119  layer enhanced_circuit_breaker;
120  #[ cfg( feature = "rate_limiting" ) ]
121  layer enhanced_rate_limiting;
122  #[ cfg( feature = "retry" ) ]
123  layer enhanced_retry;
124  #[ cfg( feature = "enterprise" ) ]
125  layer enterprise;
126
127  layer environment;
128  layer error;
129
130  #[ cfg( feature = "failover" ) ]
131  layer failover;
132  #[ cfg( feature = "health_checks" ) ]
133  layer health_checks;
134
135  layer metrics_framework;
136  layer model_deployment;
137  layer model_tuning;
138
139  #[ cfg( feature = "model_comparison" ) ]
140  layer model_comparison;
141  #[ cfg( feature = "request_templates" ) ]
142  layer request_templates;
143  #[ cfg( feature = "buffered_streaming" ) ]
144  layer buffered_streaming;
145
146  #[ cfg( all( feature = "caching", feature = "compression" ) ) ]
147  layer performance_cache;
148
149  layer performance_monitoring;
150  layer platform_specific;
151
152  #[ cfg( feature = "input_validation" ) ]
153  layer input_validation;
154  #[ cfg( feature = "input_validation" ) ]
155  layer request_validation;
156
157  #[ cfg( feature = "batching" ) ]
158  layer request_batching;
159
160  layer request_cache;
161  layer request_cache_enhanced;
162
163  #[ cfg( feature = "caching" ) ]
164  layer response_cache;
165
166  layer secret;
167  #[ cfg( feature = "streaming_control" ) ]
168  layer streaming_control;
169  layer streaming_performance_enhanced;
170  layer sync;
171  #[ cfg( feature = "websocket" ) ]
172  layer websocket_reliability_enhanced;
173  layer websocket_streaming;
174
175  exposed use admin;
176  exposed use advanced_auth;
177  exposed use builder_enhancements;
178  exposed use client_api_accessors;
179  exposed use enhanced_batch_operations;
180  exposed use enhanced_client;
181  exposed use enhanced_client_builder;
182  exposed use enhanced_client_performance;
183  // Temporarily disabled due to compilation errors
184  #[ cfg( feature = "batching" ) ]
185  exposed use enhanced_embeddings;
186  exposed use components;
187  exposed use connection_manager;
188  exposed use curl_generation;
189  exposed use diagnostics;
190  exposed use dynamic_configuration;
191
192  // Feature-gated exposed modules
193  #[ cfg( feature = "circuit_breaker" ) ]
194  exposed use enhanced_circuit_breaker;
195  #[ cfg( feature = "rate_limiting" ) ]
196  exposed use enhanced_rate_limiting;
197  #[ cfg( feature = "retry" ) ]
198  exposed use enhanced_retry;
199  #[ cfg( feature = "enterprise" ) ]
200  exposed use enterprise;
201
202  exposed use environment;
203
204  #[ cfg( feature = "failover" ) ]
205  exposed use failover;
206  #[ cfg( feature = "health_checks" ) ]
207  exposed use health_checks;
208
209  exposed use metrics_framework;
210  exposed use model_deployment;
211  exposed use model_tuning;
212
213  #[ cfg( feature = "model_comparison" ) ]
214  exposed use model_comparison;
215  #[ cfg( feature = "request_templates" ) ]
216  exposed use request_templates;
217  #[ cfg( feature = "buffered_streaming" ) ]
218  exposed use buffered_streaming;
219
220  #[ cfg( all( feature = "caching", feature = "compression" ) ) ]
221  exposed use performance_cache;
222
223  exposed use performance_monitoring;
224  exposed use platform_specific;
225
226  #[ cfg( feature = "batching" ) ]
227  exposed use request_batching;
228
229  exposed use request_cache;
230  exposed use request_cache_enhanced;
231
232  #[ cfg( feature = "caching" ) ]
233  exposed use response_cache;
234
235  exposed use secret;
236  #[ cfg( feature = "streaming_control" ) ]
237  exposed use streaming_control;
238  exposed use streaming_performance_enhanced;
239  exposed use sync;
240  exposed use uploads;
241  #[ cfg( feature = "websocket" ) ]
242  exposed use websocket_reliability_enhanced;
243  exposed use websocket_streaming;
244  exposed use error;
245  exposed use client;
246}