pub struct OpenAICompatibleConfig {
pub api_key: Option<String>,
pub base_url: String,
pub model: String,
pub temperature: Option<f32>,
pub max_tokens: Option<usize>,
pub top_p: Option<f32>,
pub extra_headers: Vec<(String, String)>,
/* private fields */
}Expand description
Configuration for a generic OpenAI-compatible chat endpoint.
Construct either explicitly for a private/self-hosted endpoint
(OpenAICompatibleConfig::new, keyless by default — opt in with
with_api_key), or through a hosted preset
(groq / openrouter /
xai).
Fields§
§api_key: Option<String>Bearer token. None sends no Authorization header at all
(keyless local servers).
base_url: StringBase URL ending at the /v1-style root; /chat/completions is appended.
model: StringFree-form model id served by the endpoint.
temperature: Option<f32>Sampling temperature.
max_tokens: Option<usize>Maximum number of tokens to generate.
top_p: Option<f32>Nucleus sampling probability mass.
extra_headers: Vec<(String, String)>Additional HTTP headers on every request (tenant headers, attribution).
Implementations§
Source§impl OpenAICompatibleConfig
impl OpenAICompatibleConfig
Sourcepub fn new(base_url: impl Into<String>, model: impl Into<String>) -> Self
pub fn new(base_url: impl Into<String>, model: impl Into<String>) -> Self
Config for a custom (often self-hosted/private) endpoint.
Keyless by default — many local servers ignore auth, and no
Authorization header is sent until
with_api_key is called.
Sourcepub fn groq(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn groq(api_key: impl Into<String>, model: impl Into<String>) -> Self
Groq preset: https://api.groq.com/openai/v1.
Sourcepub fn openrouter(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn openrouter(api_key: impl Into<String>, model: impl Into<String>) -> Self
OpenRouter preset: https://openrouter.ai/api/v1.
model is a vendor-qualified id such as "anthropic/claude-sonnet-4-5"
or "openai/gpt-5".
Sourcepub fn xai(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn xai(api_key: impl Into<String>, model: impl Into<String>) -> Self
xAI (Grok) preset: https://api.x.ai/v1.
Sourcepub fn from_env_result() -> Result<Self, ProviderError>
pub fn from_env_result() -> Result<Self, ProviderError>
Generic config from environment variables.
OPENAI_COMPATIBLE_BASE_URL(required)OPENAI_COMPATIBLE_MODEL(required)OPENAI_COMPATIBLE_API_KEY(optional; unset ⇒ keyless local endpoint)
Sourcepub fn groq_from_env() -> Result<Self, ProviderError>
pub fn groq_from_env() -> Result<Self, ProviderError>
Groq preset from GROQ_API_KEY (+ optional GROQ_MODEL, GROQ_BASE_URL).
Sourcepub fn openrouter_from_env() -> Result<Self, ProviderError>
pub fn openrouter_from_env() -> Result<Self, ProviderError>
OpenRouter preset from OPENROUTER_API_KEY + OPENROUTER_MODEL.
Optional attribution: OPENROUTER_SITE_URL, OPENROUTER_SITE_NAME.
Sourcepub fn xai_from_env() -> Result<Self, ProviderError>
pub fn xai_from_env() -> Result<Self, ProviderError>
xAI preset from XAI_API_KEY (+ optional XAI_MODEL, XAI_BASE_URL).
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 bearer token (enables the Authorization header).
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Overrides the base URL (preset users can point at a mirror/gateway).
Sourcepub fn with_model(self, model: impl Into<String>) -> Self
pub fn with_model(self, model: impl Into<String>) -> Self
Sets the model id.
Sourcepub fn with_temperature(self, temp: f32) -> Self
pub fn with_temperature(self, temp: f32) -> Self
Sets the temperature parameter.
Sourcepub fn with_max_tokens(self, max: usize) -> Self
pub fn with_max_tokens(self, max: usize) -> Self
Sets the max tokens limit.
Sourcepub fn with_top_p(self, top_p: f32) -> Self
pub fn with_top_p(self, top_p: f32) -> Self
Sets the top_p parameter.
Sourcepub fn with_extra_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_extra_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Appends one extra HTTP header sent on every request.
Trait Implementations§
Source§impl Clone for OpenAICompatibleConfig
impl Clone for OpenAICompatibleConfig
Source§fn clone(&self) -> OpenAICompatibleConfig
fn clone(&self) -> OpenAICompatibleConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more