pub struct AzureConfig {
pub azure_endpoint: Option<String>,
pub azure_deployment: Option<String>,
pub api_version: Option<String>,
pub api_key: Option<String>,
pub azure_ad_token: Option<String>,
}Expand description
Configuration builder for Azure OpenAI deployments.
Azure OpenAI uses different URL construction and authentication compared to the standard OpenAI API:
- URL:
{endpoint}/openai/deployments/{deployment}or{endpoint}/openai - Auth:
api-keyheader (notAuthorization: Bearer) - Query:
api-versionparameter on every request
§Examples
use openai_oxide::{OpenAI, AzureConfig};
let client = OpenAI::azure(
AzureConfig::new()
.azure_endpoint("https://my-resource.openai.azure.com")
.azure_deployment("gpt-4")
.api_version("2024-10-21")
.api_key("my-azure-api-key")
)?;
// All resources work the same as with the standard client
let response = client.chat().completions().create(request).await?;Fields§
§azure_endpoint: Option<String>Azure endpoint URL, e.g. https://my-resource.openai.azure.com.
azure_deployment: Option<String>Azure deployment name, e.g. gpt-4.
api_version: Option<String>Azure API version, e.g. 2024-10-21.
api_key: Option<String>Azure API key (mutually exclusive with azure_ad_token).
azure_ad_token: Option<String>Azure AD token for authentication (mutually exclusive with api_key).
Implementations§
Source§impl AzureConfig
impl AzureConfig
Sourcepub fn azure_endpoint(self, endpoint: impl Into<String>) -> Self
pub fn azure_endpoint(self, endpoint: impl Into<String>) -> Self
Set the Azure endpoint URL.
Example: https://my-resource.openai.azure.com
Sourcepub fn azure_deployment(self, deployment: impl Into<String>) -> Self
pub fn azure_deployment(self, deployment: impl Into<String>) -> Self
Set the Azure deployment name.
When set, the base URL becomes {endpoint}/openai/deployments/{deployment}.
When not set, the base URL is {endpoint}/openai.
Sourcepub fn api_version(self, version: impl Into<String>) -> Self
pub fn api_version(self, version: impl Into<String>) -> Self
Set the Azure API version.
Defaults to 2024-10-21 if not set and not in environment.
Sourcepub fn api_key(self, key: impl Into<String>) -> Self
pub fn api_key(self, key: impl Into<String>) -> Self
Set the Azure API key.
Mutually exclusive with azure_ad_token.
Sourcepub fn azure_ad_token(self, token: impl Into<String>) -> Self
pub fn azure_ad_token(self, token: impl Into<String>) -> Self
Set the Azure AD token for authentication.
Mutually exclusive with api_key. When using AD token auth,
requests use Authorization: Bearer {token} instead of api-key header.
Sourcepub fn build(self) -> Result<OpenAI, OpenAIError>
pub fn build(self) -> Result<OpenAI, OpenAIError>
Build an OpenAI client from this Azure configuration.
§Errors
Returns OpenAIError::InvalidArgument if:
- No endpoint is provided (and
AZURE_OPENAI_ENDPOINTis not set) - No credentials are provided (neither API key nor AD token)
- Both
api_keyandazure_ad_tokenare set (mutually exclusive)
Sourcepub fn from_env() -> Result<OpenAI, OpenAIError>
pub fn from_env() -> Result<OpenAI, OpenAIError>
Build an OpenAI client from environment variables.
Reads:
AZURE_OPENAI_API_KEY— API keyAZURE_OPENAI_ENDPOINT— Azure endpoint URLOPENAI_API_VERSION— API version (defaults to2024-10-21)AZURE_OPENAI_AD_TOKEN— Azure AD token (alternative to API key)
Trait Implementations§
Source§impl Clone for AzureConfig
impl Clone for AzureConfig
Source§fn clone(&self) -> AzureConfig
fn clone(&self) -> AzureConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more