objectiveai_api/ctx/ctx_ext.rs
1//! Context extension trait for per-request customization.
2
3use crate::chat;
4
5/// Extension trait for providing per-request customization.
6///
7/// Implementations can provide BYOK (Bring Your Own Key) API keys
8/// for upstream providers, allowing users to use their own API keys
9/// instead of ObjectiveAI's pooled keys.
10#[async_trait::async_trait]
11pub trait ContextExt {
12 /// Returns the user's BYOK API key for the given upstream provider.
13 ///
14 /// Returns `Ok(None)` if the user has not configured a BYOK key
15 /// for this upstream, in which case the locally configured key will be used.
16 async fn get_byok(
17 &self,
18 upstream: chat::completions::upstream::Upstream,
19 ) -> Result<Option<String>, objectiveai::error::ResponseError>;
20}