Skip to main content

objectiveai_sdk/auth/
api_key.rs

1//! API key types and definitions.
2
3use crate::prefixed_uuid::PrefixedUuid;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7/// An ObjectiveAI API Key.
8///
9/// The format is always `apk` followed by 32 hexadecimal characters
10/// representing a UUID (e.g., `apk1234567890abcdef1234567890abcdef`).
11///
12/// API keys are used to authenticate requests to the ObjectiveAI API.
13pub type ApiKey = PrefixedUuid<'a', 'p', 'k'>;
14
15/// An ObjectiveAI API Key with associated metadata.
16///
17/// This struct contains the API key itself along with information about
18/// when it was created, when it expires (if ever), whether it has been
19/// disabled, and user-provided name and description.
20#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
21#[schemars(rename = "auth.ApiKeyWithMetadata")]
22pub struct ApiKeyWithMetadata {
23    /// The API key itself.
24    pub api_key: ApiKey,
25    /// The timestamp when the API key was created (RFC 3339 format).
26    pub created: chrono::DateTime<chrono::Utc>,
27    /// The timestamp when the API key expires, or `None` if it does not expire.
28    pub expires: Option<chrono::DateTime<chrono::Utc>>,
29    /// The timestamp when the API key was disabled, or `None` if it is active.
30    pub disabled: Option<chrono::DateTime<chrono::Utc>>,
31    /// The user-provided name of the API key.
32    pub name: String,
33    /// The user-provided description of the API key, or `None` if not provided.
34    pub description: Option<String>,
35}