pub struct OpenAiCompatibleModelProvider {
pub alias: String,
pub name: String,
pub base_url: String,
pub credential: Option<String>,
pub auth_header: AuthStyle,
/* private fields */
}Expand description
A model_provider that speaks the OpenAI-compatible chat completions API.
Used by: Venice, Vercel AI Gateway, Cloudflare AI Gateway, Moonshot,
Synthetic, OpenCode Zen, OpenCode Go, Z.AI, GLM, MiniMax, Bedrock, Qianfan, Groq, Mistral, xAI, etc.
Fields§
§alias: String[providers.models.<alias>] key this provider was constructed
under. Used by the Attributable impl so log emissions carry the
real composite (<type>.<alias>) instead of the bare type.
name: String§base_url: String§credential: Option<String>§auth_header: AuthStyleImplementations§
Source§impl OpenAiCompatibleModelProvider
impl OpenAiCompatibleModelProvider
pub fn new( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, ) -> Self
pub fn new_with_vision( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, supports_vision: bool, ) -> Self
Sourcepub fn new_with_user_agent(
alias: &str,
name: &str,
base_url: &str,
credential: Option<&str>,
auth_style: AuthStyle,
user_agent: &str,
) -> Self
pub fn new_with_user_agent( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, user_agent: &str, ) -> Self
Create a model_provider with a custom User-Agent header.
Some model_providers (for example Kimi Code) require a specific User-Agent for request routing and policy enforcement.
pub fn new_with_user_agent_and_vision( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, user_agent: &str, supports_vision: bool, ) -> Self
Sourcepub fn new_merge_system_into_user(
alias: &str,
name: &str,
base_url: &str,
credential: Option<&str>,
auth_style: AuthStyle,
) -> Self
pub fn new_merge_system_into_user( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, ) -> Self
For model_providers that do not support role: system (e.g. MiniMax).
System prompt content is prepended to the first user message instead.
Sourcepub fn with_local_model_tool_sanitize(self) -> Self
pub fn with_local_model_tool_sanitize(self) -> Self
Opt this provider into per-model conservative tool-schema sanitization.
Today the only trigger is the gemma-4 family on llama.cpp, where the
upstream tool-call parser rejects empty-properties / non-string
default values. The check runs at convert-time against the runtime
model id (not against the family) so the same provider instance
happily serves llama, qwen, etc. without sanitization.
pub fn with_unauthenticated_model_listing(self) -> Self
Sourcepub fn without_native_tools(self) -> Self
pub fn without_native_tools(self) -> Self
Disable native tool calling, forcing prompt-guided tool use instead.
Sourcepub fn with_merge_system_into_user(self) -> Self
pub fn with_merge_system_into_user(self) -> Self
Merge all system messages into the first user message before sending.
Unlike new_merge_system_into_user, this preserves native tool calling.
Sourcepub fn with_timeout_secs(self, timeout_secs: u64) -> Self
pub fn with_timeout_secs(self, timeout_secs: u64) -> Self
Override the HTTP request timeout for LLM API calls.
Sourcepub fn with_extra_headers(self, headers: HashMap<String, String>) -> Self
pub fn with_extra_headers(self, headers: HashMap<String, String>) -> Self
Set extra HTTP headers to include in all API requests.
Sourcepub fn with_reasoning_effort(self, reasoning_effort: Option<String>) -> Self
pub fn with_reasoning_effort(self, reasoning_effort: Option<String>) -> Self
Set reasoning effort for GPT-5/Codex-compatible chat-completions APIs.
Sourcepub fn with_api_path(self, api_path: Option<String>) -> Self
pub fn with_api_path(self, api_path: Option<String>) -> Self
Set a custom API path suffix for this model_provider.
When set, replaces the default /chat/completions path.
Sourcepub fn with_max_tokens(self, max_tokens: Option<u32>) -> Self
pub fn with_max_tokens(self, max_tokens: Option<u32>) -> Self
Set the maximum output tokens for API requests.
Sourcepub fn with_models_dev_key(self, key: &str) -> Self
pub fn with_models_dev_key(self, key: &str) -> Self
Set the models.dev catalog key for this model_provider.
When set, list_models returns the catalog’s model list for that key.
Sourcepub fn with_openrouter_vendor_prefix(self, prefix: &str) -> Self
pub fn with_openrouter_vendor_prefix(self, prefix: &str) -> Self
Set the OpenRouter vendor prefix for this model_provider (e.g. "x-ai",
"tencent", "rekaai"). list_models falls back to this catalog when
neither a credential nor a working models.dev entry is available.
Trait Implementations§
Source§impl Clone for OpenAiCompatibleModelProvider
impl Clone for OpenAiCompatibleModelProvider
Source§fn clone(&self) -> OpenAiCompatibleModelProvider
fn clone(&self) -> OpenAiCompatibleModelProvider
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ModelProvider for OpenAiCompatibleModelProvider
impl ModelProvider for OpenAiCompatibleModelProvider
Source§fn capabilities(&self) -> ProviderCapabilities
fn capabilities(&self) -> ProviderCapabilities
Source§fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn chat_with_system<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system_prompt: Option<&'life1 str>,
message: &'life2 str,
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn chat_with_system<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system_prompt: Option<&'life1 str>,
message: &'life2 str,
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
simple_chat for
the temperature contract.Source§fn chat_with_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn chat_with_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
simple_chat for the temperature
contract.Source§fn chat_with_tools<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
tools: &'life2 [Value],
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ProviderChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn chat_with_tools<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ChatMessage],
tools: &'life2 [Value],
model: &'life3 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ProviderChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
simple_chat for the temperature contract.Source§fn chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: ProviderChatRequest<'life1>,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ProviderChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: ProviderChatRequest<'life1>,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<ProviderChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
simple_chat for
the temperature contract.Source§fn supports_native_tools(&self) -> bool
fn supports_native_tools(&self) -> bool
Source§fn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Source§fn supports_streaming_tool_events(&self) -> bool
fn supports_streaming_tool_events(&self) -> bool
Source§fn stream_chat(
&self,
request: ProviderChatRequest<'_>,
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> BoxStream<'static, StreamResult<StreamEvent>>
fn stream_chat( &self, request: ProviderChatRequest<'_>, model: &str, temperature: Option<f64>, options: StreamOptions, ) -> BoxStream<'static, StreamResult<StreamEvent>>
simple_chat for the
temperature contract.Source§fn stream_chat_with_system(
&self,
system_prompt: Option<&str>,
message: &str,
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> BoxStream<'static, StreamResult<StreamChunk>>
fn stream_chat_with_system( &self, system_prompt: Option<&str>, message: &str, model: &str, temperature: Option<f64>, options: StreamOptions, ) -> BoxStream<'static, StreamResult<StreamChunk>>
simple_chat for
the temperature contract.Source§fn stream_chat_with_history(
&self,
messages: &[ChatMessage],
model: &str,
temperature: Option<f64>,
options: StreamOptions,
) -> BoxStream<'static, StreamResult<StreamChunk>>
fn stream_chat_with_history( &self, messages: &[ChatMessage], model: &str, temperature: Option<f64>, options: StreamOptions, ) -> BoxStream<'static, StreamResult<StreamChunk>>
simple_chat for the temperature
contract.Source§fn warmup<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn warmup<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn default_temperature(&self) -> f64
fn default_temperature(&self) -> f64
None. Override per family.Source§fn default_max_tokens(&self) -> u32
fn default_max_tokens(&self) -> u32
Source§fn default_timeout_secs(&self) -> u64
fn default_timeout_secs(&self) -> u64
Source§fn default_base_url(&self) -> Option<&str>
fn default_base_url(&self) -> Option<&str>
const &'static strs
without allocations. None = model_provider has no universal endpoint
(local model_providers, auth-less CLIs, user-BYO endpoints).Source§fn default_wire_api(&self) -> &str
fn default_wire_api(&self) -> &str
"responses" (OpenAI Codex-style) or
"chat_completions" (everything else). Providers override to their
native format.Source§fn convert_tools(&self, tools: &[ToolSpec]) -> ToolsPayload
fn convert_tools(&self, tools: &[ToolSpec]) -> ToolsPayload
Source§fn simple_chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 str,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn simple_chat<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
message: &'life1 str,
model: &'life2 str,
temperature: Option<f64>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Source§fn supports_vision(&self) -> bool
fn supports_vision(&self) -> bool
Auto Trait Implementations§
impl Freeze for OpenAiCompatibleModelProvider
impl RefUnwindSafe for OpenAiCompatibleModelProvider
impl Send for OpenAiCompatibleModelProvider
impl Sync for OpenAiCompatibleModelProvider
impl Unpin for OpenAiCompatibleModelProvider
impl UnsafeUnpin for OpenAiCompatibleModelProvider
impl UnwindSafe for OpenAiCompatibleModelProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more