Skip to main content

OpenAiCompatibleModelProvider

Struct OpenAiCompatibleModelProvider 

Source
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: AuthStyle

Implementations§

Source§

impl OpenAiCompatibleModelProvider

Source

pub fn new( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, ) -> Self

Source

pub fn new_with_vision( alias: &str, name: &str, base_url: &str, credential: Option<&str>, auth_style: AuthStyle, supports_vision: bool, ) -> Self

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn with_unauthenticated_model_listing(self) -> Self

Source

pub fn without_native_tools(self) -> Self

Disable native tool calling, forcing prompt-guided tool use instead.

Source

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.

Source

pub fn with_timeout_secs(self, timeout_secs: u64) -> Self

Override the HTTP request timeout for LLM API calls.

Source

pub fn with_extra_headers(self, headers: HashMap<String, String>) -> Self

Set extra HTTP headers to include in all API requests.

Source

pub fn with_reasoning_effort(self, reasoning_effort: Option<String>) -> Self

Set reasoning effort for GPT-5/Codex-compatible chat-completions APIs.

Source

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.

Source

pub fn with_max_tokens(self, max_tokens: Option<u32>) -> Self

Set the maximum output tokens for API requests.

Source

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.

Source

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 Attributable for OpenAiCompatibleModelProvider

Source§

fn role(&self) -> Role

Source§

fn alias(&self) -> &str

Source§

impl Clone for OpenAiCompatibleModelProvider

Source§

fn clone(&self) -> OpenAiCompatibleModelProvider

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ModelProvider for OpenAiCompatibleModelProvider

Source§

fn capabilities(&self) -> ProviderCapabilities

Query model_provider capabilities.
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,

Fetch the list of available model IDs for this model_provider. Read more
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,

One-shot chat with optional system prompt. See 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,

Multi-turn conversation. See 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,

Chat with tool definitions for native function calling support. See 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,

Structured chat API for agent loop callers. See simple_chat for the temperature contract.
Source§

fn supports_native_tools(&self) -> bool

Whether model_provider supports native tool calls over API.
Source§

fn supports_streaming(&self) -> bool

Whether model_provider supports streaming responses.
Source§

fn supports_streaming_tool_events(&self) -> bool

Whether model_provider can emit structured tool-call stream events.
Source§

fn stream_chat( &self, request: ProviderChatRequest<'_>, model: &str, temperature: Option<f64>, options: StreamOptions, ) -> BoxStream<'static, StreamResult<StreamEvent>>

Structured streaming chat interface. See 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>>

Streaming chat with optional system prompt. See 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>>

Streaming chat with history. See 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,

Warm up the HTTP connection pool.
Source§

fn default_temperature(&self) -> f64

Temperature used when the caller passes None. Override per family.
Source§

fn default_max_tokens(&self) -> u32

Max output tokens used when the caller / config doesn’t set one.
Source§

fn default_timeout_secs(&self) -> u64

HTTP timeout (seconds) used when the caller / config doesn’t set one.
Source§

fn default_base_url(&self) -> Option<&str>

Canonical public API endpoint, when there is one. Returned as a string slice so model_provider impls can serve from 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

Wire protocol variant. Either "responses" (OpenAI Codex-style) or "chat_completions" (everything else). Providers override to their native format.
Source§

fn convert_tools(&self, tools: &[ToolSpec]) -> ToolsPayload

Convert tool specifications to provider-native format.
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,

Simple one-shot chat (single user message, no explicit system prompt). Read more
Source§

fn supports_vision(&self) -> bool

Whether model_provider supports multimodal vision input.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more