Skip to main content

objectiveai_sdk/auth/
response.rs

1//! Response types for authentication API endpoints.
2//!
3//! This module contains response structures returned by the authentication
4//! endpoints, including credit balances, API key metadata, and OpenRouter
5//! BYOK configuration.
6
7use serde::{Deserialize, Serialize};
8use schemars::JsonSchema;
9
10/// Response containing the user's credit balance information.
11///
12/// Credits are the billing unit for ObjectiveAI. This response provides
13/// a complete view of the user's credit status.
14#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
15#[schemars(rename = "auth.GetCreditsResponse")]
16pub struct GetCreditsResponse {
17    /// The current available credit balance.
18    #[serde(deserialize_with = "crate::serde_util::decimal")]
19    #[schemars(with = "f64")]
20    pub credits: rust_decimal::Decimal,
21    /// The total amount of credits ever purchased.
22    #[serde(deserialize_with = "crate::serde_util::decimal")]
23    #[schemars(with = "f64")]
24    pub total_credits_purchased: rust_decimal::Decimal,
25    /// The total amount of credits consumed by API usage.
26    #[serde(deserialize_with = "crate::serde_util::decimal")]
27    #[schemars(with = "f64")]
28    pub total_credits_used: rust_decimal::Decimal,
29}
30
31/// Response when creating a new API key.
32///
33/// Returns the complete API key with all associated metadata.
34pub type CreateApiKeyResponse = super::ApiKeyWithMetadata;
35
36/// Response when disabling an API key.
37///
38/// Returns the API key metadata, now including the `disabled` timestamp.
39pub type DisableApiKeyResponse = super::ApiKeyWithMetadata;
40
41/// Response containing a list of API keys.
42#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
43#[schemars(rename = "auth.ListApiKeyResponse")]
44pub struct ListApiKeyResponse {
45    /// The list of API keys with their metadata and usage costs.
46    pub data: Vec<ListApiKeyItem>,
47}
48
49/// An API key with metadata and accumulated cost information.
50///
51/// This extends [`ApiKeyWithMetadata`](super::ApiKeyWithMetadata) with
52/// the total cost incurred by requests using this key.
53#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
54#[schemars(rename = "auth.ListApiKeyItem")]
55pub struct ListApiKeyItem {
56    /// The API key and its metadata.
57    #[serde(flatten)]
58    pub inner: super::ApiKeyWithMetadata,
59    /// The total cost incurred by this API key.
60    #[serde(deserialize_with = "crate::serde_util::decimal")]
61    #[schemars(with = "f64")]
62    pub cost: rust_decimal::Decimal,
63}
64
65/// Response containing the user's OpenRouter BYOK API key.
66#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
67#[schemars(rename = "auth.GetOpenRouterByokApiKeyResponse")]
68pub struct GetOpenRouterByokApiKeyResponse {
69    /// The OpenRouter API key, or `None` if not configured.
70    pub api_key: Option<String>,
71}
72
73/// Response when creating or updating an OpenRouter BYOK API key.
74pub type CreateOpenRouterByokApiKeyResponse = GetOpenRouterByokApiKeyResponse;