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
34// When `reqwest-012` feature is enabled, alias reqwest012 → reqwest.
35// Code uses `reqwest::` everywhere — this makes 0.12 transparent.
36// Consumer adds: openai-oxide = { features = ["reqwest-012"] }
37// Cargo unifies with their workspace's reqwest 0.12, avoiding dual versions.
38#[cfg(feature = "reqwest-012")]
39extern crate reqwest012 as reqwest;
40
41pub mod azure;
42pub mod client;
43pub mod config;
44pub mod error;
45#[cfg(feature = "responses")]
46pub mod hedged;
47#[cfg(not(target_arch = "wasm32"))]
48pub mod middleware;
49pub mod pagination;
50#[cfg(feature = "structured")]
51pub mod parsing;
52#[cfg(not(target_arch = "wasm32"))]
53pub mod rate_limit;
54pub mod request_options;
55pub mod resources;
56pub(crate) mod runtime;
57pub mod stream_helpers;
58pub mod streaming;
59pub mod types;
60#[cfg(feature = "websocket")]
61pub mod websocket;
62#[cfg(feature = "websocket")]
63pub mod ws_pool;
64
65#[cfg(not(target_arch = "wasm32"))]
66pub(crate) fn ensure_tls_provider() {
67 use std::sync::Once;
68
69 static INIT: Once = Once::new();
70
71 INIT.call_once(|| {
72 let _ = rustls::crypto::ring::default_provider().install_default();
73 });
74}
75
76pub use azure::AzureConfig;
77pub use client::OpenAI;
78pub use config::ClientConfig;
79pub use error::OpenAIError;
80#[cfg(feature = "responses")]
81pub use hedged::{hedged_request, hedged_request_n, speculative};
82pub use pagination::Paginator;
83pub use request_options::RequestOptions;
84pub use streaming::SseStream;
85#[cfg(feature = "websocket")]
86pub use websocket::{WsEventStream, WsSession};