pub struct OpenRouterClient { /* private fields */ }Expand description
OpenRouter API client
OpenRouter is a unified interface for LLMs that provides:
- Access to 100+ models from various providers
- OpenAI-compatible API
- Automatic fallback and routing
Implementations§
Source§impl OpenRouterClient
impl OpenRouterClient
Sourcepub fn from_env() -> Result<Self, LlmError>
pub fn from_env() -> Result<Self, LlmError>
Create a new OpenRouter client from environment
Required: OPENROUTER_API_KEY Optional: OPENROUTER_API_BASE, OPENROUTER_APP_NAME, OPENROUTER_HTTP_REFERER
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Create a new OpenRouter client with explicit API key
Sourcepub fn with_config(
api_key: impl Into<String>,
base_url: impl Into<String>,
app_name: Option<String>,
http_referer: Option<String>,
) -> Self
pub fn with_config( api_key: impl Into<String>, base_url: impl Into<String>, app_name: Option<String>, http_referer: Option<String>, ) -> Self
Create with custom configuration
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Create with custom base URL
Sourcepub fn with_app_name(self, name: impl Into<String>) -> Self
pub fn with_app_name(self, name: impl Into<String>) -> Self
Set app name for OpenRouter rankings
Sourcepub fn with_http_referer(self, referer: impl Into<String>) -> Self
pub fn with_http_referer(self, referer: impl Into<String>) -> Self
Set HTTP referer for OpenRouter rankings
Sourcepub async fn chat_completion_with_extras(
&self,
request: ChatCompletionRequest,
extras: OpenRouterExtras,
) -> Result<ChatCompletionResponse, LlmError>
pub async fn chat_completion_with_extras( &self, request: ChatCompletionRequest, extras: OpenRouterExtras, ) -> Result<ChatCompletionResponse, LlmError>
Make a chat completion with OpenRouter-specific extras
Trait Implementations§
Source§impl Clone for OpenRouterClient
impl Clone for OpenRouterClient
Source§fn clone(&self) -> OpenRouterClient
fn clone(&self) -> OpenRouterClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OpenRouterClient
impl Debug for OpenRouterClient
Source§impl Provider for OpenRouterClient
impl Provider for OpenRouterClient
Source§fn chat_completion<'life0, 'async_trait>(
&'life0 self,
request: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat_completion<'life0, 'async_trait>(
&'life0 self,
request: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate a chat completion
Source§fn embeddings<'life0, 'async_trait>(
&'life0 self,
request: EmbeddingRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingResponse, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn embeddings<'life0, 'async_trait>(
&'life0 self,
request: EmbeddingRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingResponse, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate embeddings for text
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Get the provider name
Source§fn chat_completion_stream(
&self,
_request: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatCompletionChunk, LlmError>> + Send>>, LlmError>> + Send + '_>>
fn chat_completion_stream( &self, _request: ChatCompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatCompletionChunk, LlmError>> + Send>>, LlmError>> + Send + '_>>
Stream a chat completion
Source§fn supported_models(&self) -> Vec<String>
fn supported_models(&self) -> Vec<String>
Get the list of models supported by this provider
Auto Trait Implementations§
impl Freeze for OpenRouterClient
impl !RefUnwindSafe for OpenRouterClient
impl Send for OpenRouterClient
impl Sync for OpenRouterClient
impl Unpin for OpenRouterClient
impl UnsafeUnpin for OpenRouterClient
impl !UnwindSafe for OpenRouterClient
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
Mutably borrows from an owned value. Read more