Skip to main content

objectiveai_api/auth/
client.rs

1//! Authentication client trait definition.
2
3use crate::ctx;
4
5/// Trait for authentication operations.
6///
7/// Provides methods for managing API keys, BYOK OpenRouter keys, and credits.
8/// Generic over `CTXEXT` to allow custom context extensions.
9#[async_trait::async_trait]
10pub trait Client<CTXEXT> {
11    /// Creates a new API key for the authenticated user.
12    async fn create_api_key(
13        &self,
14        ctx: ctx::Context<CTXEXT>,
15        request: objectiveai::auth::request::CreateApiKeyRequest,
16    ) -> Result<
17        objectiveai::auth::response::CreateApiKeyResponse,
18        objectiveai::error::ResponseError,
19    >;
20
21    /// Sets the user's BYOK (Bring Your Own Key) OpenRouter API key.
22    async fn create_openrouter_byok_api_key(
23        &self,
24        ctx: ctx::Context<CTXEXT>,
25        request: objectiveai::auth::request::CreateOpenRouterByokApiKeyRequest,
26    ) -> Result<
27        objectiveai::auth::response::CreateOpenRouterByokApiKeyResponse,
28        objectiveai::error::ResponseError,
29    >;
30
31    /// Disables an existing API key.
32    async fn disable_api_key(
33        &self,
34        ctx: ctx::Context<CTXEXT>,
35        request: objectiveai::auth::request::DisableApiKeyRequest,
36    ) -> Result<
37        objectiveai::auth::response::DisableApiKeyResponse,
38        objectiveai::error::ResponseError,
39    >;
40
41    /// Deletes the user's BYOK OpenRouter API key.
42    async fn delete_openrouter_byok_api_key(
43        &self,
44        ctx: ctx::Context<CTXEXT>,
45    ) -> Result<(), objectiveai::error::ResponseError>;
46
47    /// Lists all API keys for the authenticated user.
48    async fn list_api_keys(
49        &self,
50        ctx: ctx::Context<CTXEXT>,
51    ) -> Result<
52        objectiveai::auth::response::ListApiKeyResponse,
53        objectiveai::error::ResponseError,
54    >;
55
56    /// Retrieves the user's BYOK OpenRouter API key.
57    async fn get_openrouter_byok_api_key(
58        &self,
59        ctx: ctx::Context<CTXEXT>,
60    ) -> Result<
61        objectiveai::auth::response::GetOpenRouterByokApiKeyResponse,
62        objectiveai::error::ResponseError,
63    >;
64
65    /// Retrieves the user's available credit balance.
66    async fn get_credits(
67        &self,
68        ctx: ctx::Context<CTXEXT>,
69    ) -> Result<
70        objectiveai::auth::response::GetCreditsResponse,
71        objectiveai::error::ResponseError,
72    >;
73}