openai_oxide/lib.rs
1//! # openai-oxide
2//!
3//! Idiomatic Rust client for the OpenAI API — 1:1 parity with the official Python SDK.
4//!
5//! ## Quick Start
6//!
7//! ```no_run
8//! use openai_oxide::{OpenAI, types::chat::*};
9//!
10//! #[tokio::main]
11//! async fn main() -> Result<(), openai_oxide::OpenAIError> {
12//! let client = OpenAI::from_env()?;
13//!
14//! let request = ChatCompletionRequest::new(
15//! "gpt-4o-mini",
16//! vec![
17//! ChatCompletionMessageParam::System {
18//! content: "You are a helpful assistant.".into(),
19//! name: None,
20//! },
21//! ChatCompletionMessageParam::User {
22//! content: UserContent::Text("Hello!".into()),
23//! name: None,
24//! },
25//! ],
26//! );
27//!
28//! let response = client.chat().completions().create(request).await?;
29//! println!("{}", response.choices[0].message.content.as_deref().unwrap_or(""));
30//! Ok(())
31//! }
32//! ```
33
34pub mod azure;
35pub mod client;
36pub mod config;
37pub mod error;
38#[cfg(feature = "responses")]
39pub mod hedged;
40pub mod middleware;
41pub mod pagination;
42#[cfg(feature = "structured")]
43pub mod parsing;
44pub mod rate_limit;
45pub mod request_options;
46pub mod resources;
47pub(crate) mod runtime;
48pub mod stream_helpers;
49pub mod streaming;
50pub mod types;
51#[cfg(feature = "websocket")]
52pub mod websocket;
53
54#[cfg(not(target_arch = "wasm32"))]
55pub(crate) fn ensure_tls_provider() {
56 use std::sync::Once;
57
58 static INIT: Once = Once::new();
59
60 INIT.call_once(|| {
61 let _ = rustls::crypto::ring::default_provider().install_default();
62 });
63}
64
65pub use azure::AzureConfig;
66pub use client::OpenAI;
67pub use config::ClientConfig;
68pub use error::OpenAIError;
69#[cfg(feature = "responses")]
70pub use hedged::{hedged_request, hedged_request_n, speculative};
71pub use pagination::Paginator;
72pub use request_options::RequestOptions;
73pub use streaming::SseStream;
74#[cfg(feature = "websocket")]
75pub use websocket::{WsEventStream, WsSession};