pub struct Config { /* private fields */ }
Expand description
Configuration for the OpenAI
client.
The configuration can be created from environment variables or manually constructed with the builder pattern.
§Environment Variables
OPENAI_API_KEY
: TheOpenAI
API key (required)OPENAI_API_BASE
: Custom base URL for the API (optional)OPENAI_ORGANIZATION
: Organization ID (optional)OPENAI_PROJECT
: Project ID (optional)OPENAI_TIMEOUT
: Request timeout in seconds (optional, default: 120)OPENAI_MAX_RETRIES
: Maximum number of retries (optional, default: 3)
§Example
ⓘ
// From environment variables
let config = Config::from_env().unwrap();
// Manual configuration
let config = Config::builder()
.api_key("your-api-key")
.timeout_seconds(60)
.max_retries(5)
.build();
Implementations§
Source§impl Config
impl Config
Sourcepub fn builder() -> ConfigBuilder
pub fn builder() -> ConfigBuilder
Create a new configuration builder.
Sourcepub fn organization(&self) -> Option<&str>
pub fn organization(&self) -> Option<&str>
Get the organization ID, if set.
Sourcepub fn timeout_seconds(&self) -> u64
pub fn timeout_seconds(&self) -> u64
Get the request timeout in seconds.
Sourcepub fn max_retries(&self) -> u32
pub fn max_retries(&self) -> u32
Get the maximum number of retries.
Sourcepub fn default_model(&self) -> &str
pub fn default_model(&self) -> &str
Get the default model to use.
Sourcepub fn auth_header(&self) -> String
pub fn auth_header(&self) -> String
Create an authorization header value.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more