Skip to main content

OpenAICompatibleConfig

Struct OpenAICompatibleConfig 

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

Base URL ending at the /v1-style root; /chat/completions is appended.

§model: String

Free-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

Source

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.

Source

pub fn groq(api_key: impl Into<String>, model: impl Into<String>) -> Self

Groq preset: https://api.groq.com/openai/v1.

Source

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".

Source

pub fn xai(api_key: impl Into<String>, model: impl Into<String>) -> Self

xAI (Grok) preset: https://api.x.ai/v1.

Source

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)
Source

pub fn groq_from_env() -> Result<Self, ProviderError>

Groq preset from GROQ_API_KEY (+ optional GROQ_MODEL, GROQ_BASE_URL).

Source

pub fn openrouter_from_env() -> Result<Self, ProviderError>

OpenRouter preset from OPENROUTER_API_KEY + OPENROUTER_MODEL.

Optional attribution: OPENROUTER_SITE_URL, OPENROUTER_SITE_NAME.

Source

pub fn xai_from_env() -> Result<Self, ProviderError>

xAI preset from XAI_API_KEY (+ optional XAI_MODEL, XAI_BASE_URL).

Source

pub fn with_api_key(self, api_key: impl Into<String>) -> Self

Sets the bearer token (enables the Authorization header).

Source

pub fn with_base_url(self, base_url: impl Into<String>) -> Self

Overrides the base URL (preset users can point at a mirror/gateway).

Source

pub fn with_model(self, model: impl Into<String>) -> Self

Sets the model id.

Source

pub fn with_temperature(self, temp: f32) -> Self

Sets the temperature parameter.

Source

pub fn with_max_tokens(self, max: usize) -> Self

Sets the max tokens limit.

Source

pub fn with_top_p(self, top_p: f32) -> Self

Sets the top_p parameter.

Source

pub fn with_extra_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self

Appends one extra HTTP header sent on every request.

Source

pub fn with_openrouter_attribution( self, site_url: impl Into<String>, site_name: impl Into<String>, ) -> Self

OpenRouter attribution headers (HTTP-Referer, X-Title) shown on the router’s analytics/leaderboard for this app.

Source

pub fn provider(&self) -> &str

Endpoint label used in error messages.

Source

pub fn base_url(&self) -> &str

Configured base URL.

Source

pub fn model(&self) -> &str

Configured model id.

Trait Implementations§

Source§

impl Clone for OpenAICompatibleConfig

Source§

fn clone(&self) -> OpenAICompatibleConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenAICompatibleConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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