pub struct OpenAiConfig {
pub base_url: String,
pub api_key: Option<String>,
pub auth: AuthStyle,
pub headers: Vec<(String, String)>,
pub query: Vec<(String, String)>,
pub include_usage: bool,
pub use_max_completion_tokens: bool,
pub connect_timeout: Duration,
pub credentials: Option<Arc<dyn CredentialSource>>,
pub credential_name: String,
}Expand description
Configuration of an OpenAI-compatible endpoint.
Fields§
§base_url: StringBase URL without the /chat/completions suffix, e.g. https://api.openai.com/v1.
api_key: Option<String>§auth: AuthStyle§headers: Vec<(String, String)>Extra headers sent with every request.
query: Vec<(String, String)>Extra query parameters (e.g. api-version).
include_usage: boolAsk for a final usage chunk (stream_options.include_usage). Disable for
endpoints that reject the field.
use_max_completion_tokens: boolSend max_completion_tokens instead of max_tokens (required by some newer models).
connect_timeout: Duration§credentials: Option<Arc<dyn CredentialSource>>Per-request credential source. When set it replaces api_key; its headers are
appended and its base_url, if any, overrides base_url. A 401/403 response
invalidates the credential and the request is retried once.
credential_name: StringProvider name passed to the credential source (default openai).
Implementations§
Source§impl OpenAiConfig
impl OpenAiConfig
pub fn new(base_url: impl Into<String>, api_key: Option<String>) -> Self
Sourcepub fn with_credentials(self, source: Arc<dyn CredentialSource>) -> Self
pub fn with_credentials(self, source: Arc<dyn CredentialSource>) -> Self
Ask source for a credential before every request (see crate::credentials).
Sourcepub fn credential_name(self, name: impl Into<String>) -> Self
pub fn credential_name(self, name: impl Into<String>) -> Self
Provider name passed to the credential source.
Source§impl OpenAiConfig
impl OpenAiConfig
Sourcepub fn azure(
endpoint: &str,
api_key: impl Into<String>,
) -> Result<Self, LlmError>
pub fn azure( endpoint: &str, api_key: impl Into<String>, ) -> Result<Self, LlmError>
Azure OpenAI through its v1 API: one provider for every deployment of the resource
(the model name of a request is the deployment name), the key in the api-key
header and max_completion_tokens (which reasoning deployments require). The v1 API
takes no api-version; push one onto query only for preview features (preview).
§Errors
LlmError::Config for an endpoint azure_openai_v1_base_url refuses.