pub struct OpenRouterClient { /* private fields */ }Expand description
Shared OpenRouter client used by the native APIs and the Llm adapter.
Implementations§
Source§impl OpenRouterClient
impl OpenRouterClient
Sourcepub fn new(config: OpenRouterConfig) -> Result<Self, AdkError>
pub fn new(config: OpenRouterConfig) -> Result<Self, AdkError>
Create a new OpenRouter client with shared default headers.
Sourcepub fn with_timeouts(self, timeouts: HttpTimeouts) -> Result<Self, AdkError>
pub fn with_timeouts(self, timeouts: HttpTimeouts) -> Result<Self, AdkError>
Sets the connect and idle timeouts of the HTTP transport, so a stalled stream fails instead of holding the run.
See HttpTimeouts for the defaults. OpenRouter’s keep-alive
comments count as data, so a slow upstream that OpenRouter is still waiting on does
not trip the idle timeout.
§Example
use std::time::Duration;
use adk_model::openrouter::{OpenRouterClient, OpenRouterConfig};
use adk_model::HttpTimeouts;
let client = OpenRouterClient::new(OpenRouterConfig::new("sk-or-key", "openai/gpt-5.6-terra"))?
.with_timeouts(HttpTimeouts::new(Duration::from_secs(10), Duration::from_secs(120)))?;§Errors
Returns model.openrouter.client_build_failed when the HTTP client cannot be built.
Sourcepub fn config(&self) -> &OpenRouterConfig
pub fn config(&self) -> &OpenRouterConfig
Borrow the immutable client configuration.
Sourcepub fn http_client(&self) -> &Client
pub fn http_client(&self) -> &Client
Borrow the shared HTTP client.
Sourcepub fn with_retry_config(self, retry_config: RetryConfig) -> Self
pub fn with_retry_config(self, retry_config: RetryConfig) -> Self
Return a new client value with the provided retry configuration.
Sourcepub fn set_retry_config(&mut self, retry_config: RetryConfig)
pub fn set_retry_config(&mut self, retry_config: RetryConfig)
Replace the retry configuration in place.
Sourcepub fn retry_config(&self) -> &RetryConfig
pub fn retry_config(&self) -> &RetryConfig
Borrow the active retry configuration.
Sourcepub fn endpoint_url(&self, path: &str) -> String
pub fn endpoint_url(&self, path: &str) -> String
Build an absolute endpoint URL for a relative OpenRouter API path.
Sourcepub async fn send_chat(
&self,
request: OpenRouterChatRequest,
) -> Result<OpenRouterChatResponse, AdkError>
pub async fn send_chat( &self, request: OpenRouterChatRequest, ) -> Result<OpenRouterChatResponse, AdkError>
Send a non-streaming chat-completions request to OpenRouter.
Sourcepub async fn send_chat_stream(
&self,
request: OpenRouterChatRequest,
) -> Result<OpenRouterChatStream, AdkError>
pub async fn send_chat_stream( &self, request: OpenRouterChatRequest, ) -> Result<OpenRouterChatStream, AdkError>
Send a streaming chat-completions request to OpenRouter.
Sourcepub async fn create_response(
&self,
request: OpenRouterResponsesRequest,
) -> Result<OpenRouterResponse, AdkError>
pub async fn create_response( &self, request: OpenRouterResponsesRequest, ) -> Result<OpenRouterResponse, AdkError>
Send a non-streaming Responses API request to OpenRouter.
Sourcepub async fn create_response_stream(
&self,
request: OpenRouterResponsesRequest,
) -> Result<OpenRouterResponsesStream, AdkError>
pub async fn create_response_stream( &self, request: OpenRouterResponsesRequest, ) -> Result<OpenRouterResponsesStream, AdkError>
Send a streaming Responses API request to OpenRouter.
Sourcepub async fn list_models(&self) -> Result<Vec<OpenRouterModel>, AdkError>
pub async fn list_models(&self) -> Result<Vec<OpenRouterModel>, AdkError>
List models available from OpenRouter discovery.
Sourcepub async fn get_model_endpoints(
&self,
author: &str,
slug: &str,
) -> Result<OpenRouterModelEndpoints, AdkError>
pub async fn get_model_endpoints( &self, author: &str, slug: &str, ) -> Result<OpenRouterModelEndpoints, AdkError>
List provider endpoints for a discovered OpenRouter model.
Sourcepub async fn list_providers(&self) -> Result<Vec<OpenRouterProvider>, AdkError>
pub async fn list_providers(&self) -> Result<Vec<OpenRouterProvider>, AdkError>
List providers available on OpenRouter.
Sourcepub async fn get_credits(&self) -> Result<OpenRouterCredits, AdkError>
pub async fn get_credits(&self) -> Result<OpenRouterCredits, AdkError>
Get the authenticated account’s remaining credits.
Trait Implementations§
Source§impl Llm for OpenRouterClient
impl Llm for OpenRouterClient
Source§fn data_destinations(&self) -> Vec<DataDestination>
fn data_destinations(&self) -> Vec<DataDestination>
LlmResponse::provider, with the hosts its client connects to. Read moreSource§fn generate_content<'life0, 'async_trait>(
&'life0 self,
request: LlmRequest,
stream: bool,
) -> Pin<Box<dyn Future<Output = Result<LlmResponseStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn generate_content<'life0, 'async_trait>(
&'life0 self,
request: LlmRequest,
stream: bool,
) -> Pin<Box<dyn Future<Output = Result<LlmResponseStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn generate_content_metered<'life0, 'life1, 'async_trait>(
&'life0 self,
scope: &'life1 ModelCallScope,
req: LlmRequest,
stream: bool,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LlmResponse, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn generate_content_metered<'life0, 'life1, 'async_trait>(
&'life0 self,
scope: &'life1 ModelCallScope,
req: LlmRequest,
stream: bool,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LlmResponse, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
scope. Read moreSource§fn schema_adapter(&self) -> &dyn SchemaAdapter
fn schema_adapter(&self) -> &dyn SchemaAdapter
Source§fn uses_interactions_api(&self) -> bool
fn uses_interactions_api(&self) -> bool
true if this model is configured to use a server-managed
environment (e.g., Gemini Interactions API) where the provider owns
the tool-calling loop and filesystem. Read moreSource§fn max_cost_micro_usd(&self, request: &LlmRequest) -> Option<u64>
fn max_cost_micro_usd(&self, request: &LlmRequest) -> Option<u64>
request can cost on this model. Read moreSource§fn context_window(&self) -> Option<u64>
fn context_window(&self) -> Option<u64>
Source§fn native_web_search(&self) -> Option<NativeWebSearch>
fn native_web_search(&self) -> Option<NativeWebSearch>
Source§fn native_compaction(&self) -> Option<NativeCompaction>
fn native_compaction(&self) -> Option<NativeCompaction>
Source§fn prewarm<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn prewarm<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Source§fn data_locality(&self) -> DataLocality
fn data_locality(&self) -> DataLocality
DataLocality::Remote),
to a server on this machine (DataLocality::Loopback), or nowhere outside this
process (DataLocality::InProcess). Read moreAuto Trait Implementations§
impl !RefUnwindSafe for OpenRouterClient
impl !UnwindSafe for OpenRouterClient
impl Forget for OpenRouterClient
impl Freeze for OpenRouterClientwhere
*const ArcInner<ClientRef> is !null: Freeze,
PhantomData<ArcInner<ClientRef>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
impl Move for OpenRouterClient
impl Send for OpenRouterClient
impl Sync for OpenRouterClient
impl Unpin for OpenRouterClient
impl UnsafeUnpin for OpenRouterClientwhere
*const ArcInner<ClientRef> is !null: UnsafeUnpin,
PhantomData<ArcInner<ClientRef>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request