pub struct AzureOpenAIProviderSettings {
pub resource_name: Option<String>,
pub base_url: Option<String>,
pub api_key: Option<String>,
pub headers: Option<HashMap<String, String>>,
pub api_version: String,
pub use_deployment_based_urls: bool,
}Expand description
Configuration options for creating an Azure OpenAI provider.
Azure OpenAI has unique authentication and URL patterns compared to standard OpenAI:
- Uses
api-keyheader instead ofAuthorization: Bearer - Requires API version in query parameters
- Supports both deployment-based and v1 API URL formats
- Can use either
resourceNameor custombaseURL
Fields§
§resource_name: Option<String>Name of the Azure OpenAI resource. Either this or base_url can be used.
The resource name is used in the assembled URL:
https://{resource_name}.openai.azure.com/openai/v1{path}
base_url: Option<String>Use a different URL prefix for API calls, e.g. to use proxy servers.
Either this or resource_name can be used.
When a base_url is provided, the resource_name is ignored.
With a base_url, the resolved URL is {base_url}/v1{path}.
api_key: Option<String>API key for authenticating requests.
If not provided, will attempt to read from AZURE_API_KEY environment variable.
headers: Option<HashMap<String, String>>Custom headers to include in the requests.
api_version: StringCustom API version to use. Defaults to “v1”.
Azure OpenAI requires an API version parameter in all requests. Common versions include “2023-05-15”, “2024-02-15-preview”, etc.
use_deployment_based_urls: boolUse deployment-based URLs for specific model types.
Set to true to use legacy deployment format:
{base_url}/deployments/{deployment_id}{path}?api-version={api_version}
Set to false (default) to use v1 API format:
{base_url}/v1{path}?api-version={api_version}
Implementations§
Source§impl AzureOpenAIProviderSettings
impl AzureOpenAIProviderSettings
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Azure OpenAI provider configuration.
You must provide either a resource_name or base_url before using the provider.
Sourcepub fn with_resource_name(self, resource_name: impl Into<String>) -> Self
pub fn with_resource_name(self, resource_name: impl Into<String>) -> Self
Sets the Azure OpenAI resource name.
The resource name is used to construct the base URL:
https://{resource_name}.openai.azure.com/openai
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Sets a custom base URL for API calls.
When set, this takes precedence over resource_name.
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Sets the API key for authentication.
Sourcepub fn with_headers(self, headers: HashMap<String, String>) -> Self
pub fn with_headers(self, headers: HashMap<String, String>) -> Self
Sets additional headers to include in requests.
Sourcepub fn with_header(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Adds a single header to include in requests.
Sourcepub fn with_api_version(self, api_version: impl Into<String>) -> Self
pub fn with_api_version(self, api_version: impl Into<String>) -> Self
Sets the API version to use in requests.
Defaults to “v1”. Common versions include “2023-05-15”, “2024-02-15-preview”, etc.
Sourcepub fn with_use_deployment_based_urls(
self,
use_deployment_based_urls: bool,
) -> Self
pub fn with_use_deployment_based_urls( self, use_deployment_based_urls: bool, ) -> Self
Sets whether to use deployment-based URLs.
When true, uses format: {base_url}/deployments/{deployment_id}{path}
When false (default), uses format: {base_url}/v1{path}
Trait Implementations§
Source§impl Clone for AzureOpenAIProviderSettings
impl Clone for AzureOpenAIProviderSettings
Source§fn clone(&self) -> AzureOpenAIProviderSettings
fn clone(&self) -> AzureOpenAIProviderSettings
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more