pub struct OpenRouterProvider { /* private fields */ }Expand description
OpenRouter API provider.
OpenRouter provides access to multiple LLM providers through a single API.
Model names use the format: provider/model-name (e.g., anthropic/claude-3-opus)
§Example
ⓘ
use converge_provider::OpenRouterProvider;
use converge_traits::llm::{LlmProvider, LlmRequest};
let provider = OpenRouterProvider::new(
"your-api-key",
"anthropic/claude-3-opus"
);
let request = LlmRequest::new("What is 2+2?");
let response = provider.complete(&request)?;
println!("{}", response.content);Implementations§
Source§impl OpenRouterProvider
impl OpenRouterProvider
Sourcepub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
Creates a new OpenRouter provider.
Sourcepub fn from_env(model: impl Into<String>) -> Result<Self, LlmError>
pub fn from_env(model: impl Into<String>) -> Result<Self, LlmError>
Creates a provider using the OPENROUTER_API_KEY environment variable.
§Errors
Returns error if the environment variable is not set.
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Uses a custom base URL (for testing or proxies).
Trait Implementations§
Source§impl LlmProvider for OpenRouterProvider
impl LlmProvider for OpenRouterProvider
Source§fn complete(&self, request: &LlmRequest) -> Result<LlmResponse, LlmError>
fn complete(&self, request: &LlmRequest) -> Result<LlmResponse, LlmError>
Sends a completion request to the LLM. Read more
Source§fn provenance(&self, request_id: &str) -> String
fn provenance(&self, request_id: &str) -> String
Returns a provenance string for tracking (e.g., “claude-3-opus:abc123”).
Source§impl OpenAiCompatibleProvider for OpenRouterProvider
impl OpenAiCompatibleProvider for OpenRouterProvider
Source§fn config(&self) -> &HttpProviderConfig
fn config(&self) -> &HttpProviderConfig
Gets the provider configuration.
Source§fn complete_openai_compatible(
&self,
request: &LlmRequest,
) -> Result<LlmResponse, LlmError>
fn complete_openai_compatible( &self, request: &LlmRequest, ) -> Result<LlmResponse, LlmError>
Makes a completion request. Read more
Auto Trait Implementations§
impl Freeze for OpenRouterProvider
impl !RefUnwindSafe for OpenRouterProvider
impl Send for OpenRouterProvider
impl Sync for OpenRouterProvider
impl Unpin for OpenRouterProvider
impl UnsafeUnpin for OpenRouterProvider
impl !UnwindSafe for OpenRouterProvider
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