pub struct ClientBuilder { /* private fields */ }Expand description
Builder for Client. Unset fields fall back to the same environment
variables the Python SDK uses: OPENAI_API_KEY, OPENAI_BASE_URL,
OPENAI_ORG_ID, OPENAI_PROJECT_ID.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
pub fn new() -> Self
Sourcepub fn api_key(self, api_key: impl Into<String>) -> Self
pub fn api_key(self, api_key: impl Into<String>) -> Self
API key used in the Authorization: Bearer header.
Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Base URL of the API, e.g. https://api.openai.com/v1 or any
OpenAI-compatible provider endpoint.
Sourcepub fn organization(self, organization: impl Into<String>) -> Self
pub fn organization(self, organization: impl Into<String>) -> Self
Sent as the OpenAI-Organization header.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Read timeout, applied per read operation (mirroring the Python SDK’s httpx behavior) so streaming responses are not cut off by a total deadline. Defaults to 600 seconds.
Sourcepub fn connect_timeout(self, connect_timeout: Duration) -> Self
pub fn connect_timeout(self, connect_timeout: Duration) -> Self
Connection timeout. Defaults to 5 seconds.
Sourcepub fn max_retries(self, max_retries: u32) -> Self
pub fn max_retries(self, max_retries: u32) -> Self
Maximum number of retries for retryable failures. Defaults to 2.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a header sent with every request.
Sourcepub fn azure(
self,
endpoint: impl Into<String>,
api_version: impl Into<String>,
) -> Self
pub fn azure( self, endpoint: impl Into<String>, api_version: impl Into<String>, ) -> Self
Target an Azure OpenAI resource, mirroring the Python AzureOpenAI
client: requests go to {endpoint}/openai[...] with an api-version
query parameter, authenticated via api-key header (or a bearer
token set with ClientBuilder::azure_ad_token).
The API key falls back to the AZURE_OPENAI_API_KEY environment
variable; api_version may be empty to use OPENAI_API_VERSION.
Sourcepub fn azure_deployment(self, deployment: impl Into<String>) -> Self
pub fn azure_deployment(self, deployment: impl Into<String>) -> Self
Pin all requests to a specific Azure deployment
({endpoint}/openai/deployments/{deployment}). Without this, the
deployment is derived per request from the body’s model field.
Sourcepub fn azure_ad_token(self, token: impl Into<String>) -> Self
pub fn azure_ad_token(self, token: impl Into<String>) -> Self
Authenticate to Azure with an Entra ID (Azure AD) bearer token
instead of an API key. Falls back to AZURE_OPENAI_AD_TOKEN.
Trait Implementations§
Source§impl Clone for ClientBuilder
impl Clone for ClientBuilder
Source§fn clone(&self) -> ClientBuilder
fn clone(&self) -> ClientBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more