agentmail/types/api_keys.rs
1use serde::{Deserialize, Serialize};
2
3/// An API key's metadata (never its secret material; see [`CreatedApiKey`]).
4#[derive(Clone, Debug, Deserialize)]
5pub struct ApiKey {
6 /// Unique key id.
7 pub api_key_id: String,
8 /// The key's non-secret prefix, for identification.
9 #[serde(default)]
10 pub prefix: Option<String>,
11 /// Human-readable name.
12 #[serde(default)]
13 pub name: Option<String>,
14 /// The pod the key is scoped to, when applicable.
15 #[serde(default)]
16 pub pod_id: Option<String>,
17 /// The inbox the key is scoped to, when applicable.
18 #[serde(default)]
19 pub inbox_id: Option<String>,
20 /// When the key was last used (RFC 3339).
21 #[serde(default)]
22 pub used_at: Option<String>,
23 /// The key's permissions.
24 #[serde(default)]
25 pub permissions: Option<serde_json::Value>,
26 /// When the key was created (RFC 3339).
27 #[serde(default)]
28 pub created_at: Option<String>,
29}
30
31/// Request body for [`Client::create_api_key`](crate::Client::create_api_key).
32#[derive(Clone, Debug, Default, Serialize)]
33pub struct CreateApiKey {
34 /// Human-readable name for the key.
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub name: Option<String>,
37 /// The permissions to grant.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub permissions: Option<serde_json::Value>,
40}
41
42/// The response to [`Client::create_api_key`](crate::Client::create_api_key). The full `api_key` secret is
43/// returned exactly once, here; store it now, as it cannot be retrieved again.
44#[derive(Clone, Debug, Deserialize)]
45pub struct CreatedApiKey {
46 /// Unique key id.
47 pub api_key_id: String,
48 /// The full secret key. Shown only on creation.
49 pub api_key: String,
50 /// The key's non-secret prefix.
51 #[serde(default)]
52 pub prefix: Option<String>,
53 /// Human-readable name.
54 #[serde(default)]
55 pub name: Option<String>,
56 /// When the key was created (RFC 3339).
57 #[serde(default)]
58 pub created_at: Option<String>,
59}
60
61/// One page of API keys from [`Client::list_api_keys_page`](crate::Client::list_api_keys_page).
62#[derive(Clone, Debug, Deserialize)]
63pub struct ApiKeyList {
64 /// Total keys in the account (not just this page).
65 pub count: u64,
66 /// This page of keys.
67 #[serde(default)]
68 pub api_keys: Vec<ApiKey>,
69 /// Cursor for the next page; `None` on the last page.
70 #[serde(default)]
71 pub next_page_token: Option<String>,
72}