API Keys Management
Relevant source files
The following files were used as context for generating this wiki page:
The API Keys Management module provides the interface for interacting with Resend's /api-keys endpoints. This system enables you to programmatically create, list, update, and delete API keys used to authenticate communications with Resend services.
API keys are essential for authenticating requests made by the Resend client. While the client requires a primary key (often set via the RESEND_API_KEY environment variable), this module allows for the administrative management of additional keys within a Resend account.
Sources: src/api_keys.rs:16, README.md:34
Architecture and Service Structure
The management of API keys is encapsulated within the ApiKeysSvc struct. This service holds an atomic reference to the global Config, which contains the HTTP client, base URL, and primary authentication credentials.
The diagram shows the relationship between the main Resend client and the ApiKeysSvc.
Sources: src/api_keys.rs:16-17, src/lib.rs:59, src/config.rs:107-113
Key Operations
Creating API Keys
You create a new API key by providing a name and optional permissions. Permissions determine if the key has full_access to all resources or is restricted to sending_access for emails only. You can further restrict sending_access keys to a specific domain ID.
Sources: src/api_keys.rs:21-27, src/api_keys.rs:85-117
Listing API Keys
The list method retrieves all API keys associated with the authenticated user. By default, this operation returns all keys without a specific limit.
Sources: src/api_keys.rs:34-40
Updating API Keys
Updates are limited to the name of the API key. Permissions and domain restrictions are fixed at the time of creation and cannot be modified.
Sources: src/api_keys.rs:46-59
Deleting API Keys
The delete method removes an existing API key from the account using its unique identifier.
Sources: src/api_keys.rs:64-72
Data Models
The following tables describe the structures used for requests and responses within the API Keys service.
API Key Permissions
| Permission | Description |
|---|---|
full_access | Can create, delete, get, and update any resource. |
sending_access | Restricted to sending emails only. |
Sources: src/api_keys.rs:125-131
Data Structures
| Struct | Field | Type | Description |
|---|---|---|---|
ApiKey | id | ApiKeyId | The unique identifier of the key. |
name | String | The display name of the key. | |
created_at | String | ISO timestamp of creation. | |
last_used_at | Option<String> | ISO timestamp of last use. | |
ApiKeyToken | id | ApiKeyId | Unique identifier (returned on create). |
token | String | The actual API token string. |
Sources: src/api_keys.rs:153-175
Authentication Flow
Requests to the API keys endpoints use the primary API key configured in the Resend client for authentication.
The diagram illustrates how the ApiKeysSvc utilizes the internal Config to authorize management requests.
Sources: src/api_keys.rs:22-26, src/config.rs:149-158
Implementation Details
The service uses maybe_async to support both synchronous and asynchronous execution depending on the enabled crate features.
// Example of updating an API key name
// Sources: src/api_keys.rs:189-191
let update = UpdateApiKeyOptions::new("test_renamed");
let response = resend.api_keys.update(&id, update).await?;
Sources: src/api_keys.rs:49, src/api_keys.rs:189-191
Summary
The API Keys Management system provides a structured way to handle authentication credentials within the Resend ecosystem. It enforces strict permission models (Full vs. Sending access) and ensures that security-critical attributes like domain restrictions remain immutable after key creation.