Skip to main content

objectiveai_api/auth/
objectiveai.rs

1//! ObjectiveAI authentication client implementation.
2
3use crate::ctx;
4use std::sync::Arc;
5
6/// Authentication client that delegates to the ObjectiveAI HTTP API.
7pub struct ObjectiveAiClient {
8    /// The underlying HTTP client for ObjectiveAI API requests.
9    pub client: Arc<objectiveai::HttpClient>,
10}
11
12impl ObjectiveAiClient {
13    /// Creates a new ObjectiveAI authentication client.
14    pub fn new(client: Arc<objectiveai::HttpClient>) -> Self {
15        Self { client }
16    }
17}
18
19#[async_trait::async_trait]
20impl<CTXEXT> super::Client<CTXEXT> for ObjectiveAiClient
21where
22    CTXEXT: Send + Sync + 'static,
23{
24    async fn create_api_key(
25        &self,
26        _ctx: ctx::Context<CTXEXT>,
27        request: objectiveai::auth::request::CreateApiKeyRequest,
28    ) -> Result<
29        objectiveai::auth::response::CreateApiKeyResponse,
30        objectiveai::error::ResponseError,
31    > {
32        objectiveai::auth::create_api_key(&self.client, request)
33            .await
34            .map_err(|e| objectiveai::error::ResponseError::from(&e))
35    }
36
37    async fn create_openrouter_byok_api_key(
38        &self,
39        _ctx: ctx::Context<CTXEXT>,
40        request: objectiveai::auth::request::CreateOpenRouterByokApiKeyRequest,
41    ) -> Result<
42        objectiveai::auth::response::CreateOpenRouterByokApiKeyResponse,
43        objectiveai::error::ResponseError,
44    > {
45        objectiveai::auth::create_openrouter_byok_api_key(&self.client, request)
46            .await
47            .map_err(|e| objectiveai::error::ResponseError::from(&e))
48    }
49
50    async fn disable_api_key(
51        &self,
52        _ctx: ctx::Context<CTXEXT>,
53        request: objectiveai::auth::request::DisableApiKeyRequest,
54    ) -> Result<
55        objectiveai::auth::response::DisableApiKeyResponse,
56        objectiveai::error::ResponseError,
57    > {
58        objectiveai::auth::disable_api_key(&self.client, request)
59            .await
60            .map_err(|e| objectiveai::error::ResponseError::from(&e))
61    }
62
63    async fn delete_openrouter_byok_api_key(
64        &self,
65        _ctx: ctx::Context<CTXEXT>,
66    ) -> Result<(), objectiveai::error::ResponseError> {
67        objectiveai::auth::delete_openrouter_byok_api_key(&self.client)
68            .await
69            .map_err(|e| objectiveai::error::ResponseError::from(&e))
70    }
71
72    async fn list_api_keys(
73        &self,
74        _ctx: ctx::Context<CTXEXT>,
75    ) -> Result<
76        objectiveai::auth::response::ListApiKeyResponse,
77        objectiveai::error::ResponseError,
78    > {
79        objectiveai::auth::list_api_keys(&self.client)
80            .await
81            .map_err(|e| objectiveai::error::ResponseError::from(&e))
82    }
83
84    async fn get_openrouter_byok_api_key(
85        &self,
86        _ctx: ctx::Context<CTXEXT>,
87    ) -> Result<
88        objectiveai::auth::response::GetOpenRouterByokApiKeyResponse,
89        objectiveai::error::ResponseError,
90    > {
91        objectiveai::auth::get_openrouter_byok_api_key(&self.client)
92            .await
93            .map_err(|e| objectiveai::error::ResponseError::from(&e))
94    }
95
96    async fn get_credits(
97        &self,
98        _ctx: ctx::Context<CTXEXT>,
99    ) -> Result<
100        objectiveai::auth::response::GetCreditsResponse,
101        objectiveai::error::ResponseError,
102    > {
103        objectiveai::auth::get_credits(&self.client)
104            .await
105            .map_err(|e| objectiveai::error::ResponseError::from(&e))
106    }
107}