Skip to main content

cognee_http_server/dto/
api_keys.rs

1//! DTOs for the api-keys router.
2
3use serde::{Deserialize, Serialize};
4use utoipa::ToSchema;
5use uuid::Uuid;
6
7/// Request body for `POST /api/v1/auth/api-keys`.
8/// Pydantic source: `ApiKeyCreationPayload(InDTO)`.
9#[derive(Debug, Deserialize, ToSchema)]
10pub struct ApiKeyCreationPayloadDTO {
11    /// User-supplied display label; nullable.
12    #[serde(default)]
13    pub name: Option<String>,
14}
15
16/// One row in the response array of `GET /api/v1/auth/api-keys`.
17#[derive(Debug, Serialize, ToSchema)]
18pub struct ApiKeyListItemDTO {
19    /// Raw 64-hex value when `HASH_API_KEY=false` (default),
20    /// or the literal `"************"` (12 asterisks) when `HASH_API_KEY=true`.
21    pub key: String,
22    /// First 8 chars of the original raw key + `"****"`.
23    pub label: String,
24    /// User-supplied display label; nullable.
25    pub name: Option<String>,
26    pub id: Uuid,
27}
28
29/// Response body for `POST /api/v1/auth/api-keys`. Returned exactly once.
30#[derive(Debug, Serialize, ToSchema)]
31pub struct ApiKeyCreatedDTO {
32    /// Raw 64-hex value. NEVER returned again — clients must persist it.
33    pub key: String,
34    pub label: String,
35    pub name: Option<String>,
36    pub id: Uuid,
37}
38
39/// 400 error envelope unique to the api-keys router.
40/// Wire shape: `{"error": {"message": "..."}}`.
41#[derive(Debug, Serialize, ToSchema)]
42pub struct ApiKeyErrorEnvelopeDTO {
43    pub error: ApiKeyErrorDetail,
44}
45
46/// Inner error detail for the api-keys router envelope.
47#[derive(Debug, Serialize, ToSchema)]
48pub struct ApiKeyErrorDetail {
49    pub message: String,
50}