pub struct CustomProviderBuilder { /* private fields */ }Expand description
Builder for OpenAI-compatible custom providers without editing the Provider enum.
This builder allows you to create a ChatProvider for any service that exposes
an OpenAI-compatible API, even if it’s not natively supported by the library.
§Example
// Create a provider for a hypothetical service "MyService"
let my_provider = CustomProviderBuilder::new("MyService")
.with_base_url("https://api.myservice.com/v1")
.with_api_key_env("MY_SERVICE_API_KEY")
.with_default_chat_model("my-model-v1")
.build_provider()?;
// Inject it into the client
let client = AiClientBuilder::new(Provider::OpenAI) // Enum ignored
.with_strategy(my_provider)
.build()?;Implementations§
Source§impl CustomProviderBuilder
impl CustomProviderBuilder
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new builder with the human-readable provider name.
Sourcepub fn with_base_url(self, base_url: &str) -> Self
pub fn with_base_url(self, base_url: &str) -> Self
Set the base URL (required) for the custom provider.
Sourcepub fn with_api_key_env(self, env_var: &str) -> Self
pub fn with_api_key_env(self, env_var: &str) -> Self
Override the environment variable used to fetch the API key at runtime.
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Inject a literal API key instead of relying on environment variables.
Sourcepub fn with_default_chat_model(self, model: &str) -> Self
pub fn with_default_chat_model(self, model: &str) -> Self
Override the default chat model used for simple helpers.
Sourcepub fn with_default_multimodal_model(self, model: &str) -> Self
pub fn with_default_multimodal_model(self, model: &str) -> Self
Override the default multimodal model (optional).
Sourcepub fn with_chat_endpoint(self, endpoint: &str) -> Self
pub fn with_chat_endpoint(self, endpoint: &str) -> Self
Override the chat completion endpoint (default: /chat/completions).
Sourcepub fn with_upload_endpoint(self, endpoint: Option<&str>) -> Self
pub fn with_upload_endpoint(self, endpoint: Option<&str>) -> Self
Override the upload endpoint (default: /v1/files).
Sourcepub fn with_models_endpoint(self, endpoint: Option<&str>) -> Self
pub fn with_models_endpoint(self, endpoint: Option<&str>) -> Self
Override the models endpoint (default: /models).
Sourcepub fn with_headers<I, K, V>(self, headers: I) -> Self
pub fn with_headers<I, K, V>(self, headers: I) -> Self
Merge custom HTTP headers (e.g., vendor-specific auth scopes).
Sourcepub fn with_transport(self, transport: DynHttpTransportRef) -> Self
pub fn with_transport(self, transport: DynHttpTransportRef) -> Self
Provide a pre-built transport (shared client, proxy, custom TLS, etc.).
Sourcepub fn build_provider(self) -> Result<Box<dyn ChatProvider>, AiLibError>
pub fn build_provider(self) -> Result<Box<dyn ChatProvider>, AiLibError>
Build a boxed ChatProvider that can be passed to AiClientBuilder::with_strategy.