Usage & Logs APIs
Relevant source files
The following files were used as context for generating this wiki page:
The Usage and Logs APIs provide programmatic access to account-level metrics and historical request data. The Usage API tracks consumption across various Resend services such as emails, contacts, and automations against their respective limits. The Logs API allows you to retrieve metadata about individual API requests, including endpoints hit, methods used, and response statuses.
Sources: src/usage.rs:11-14, src/logs.rs:14-17, src/lib.rs:125-132
Usage API
The UsageSvc retrieves account-level quota data. This service helps you monitor daily and monthly limits to avoid DailyQuotaExceeded or MonthlyQuotaExceeded errors.
Sources: src/usage.rs:9-10, src/error.rs:168-183
Usage Data Structure
The API returns a Usage struct containing specialized usage metrics for different resources.
| Field | Type | Description |
|---|---|---|
emails | EmailsUsage | Breaks down sent and received emails by daily and monthly periods. |
contacts | ContactsUsage | Current contact count vs maximum allowed. |
segments | SegmentsUsage | Created segments vs maximum allowed. |
broadcasts | BroadcastsUsage | Total number of broadcasts sent. |
ai_credits | AiCreditsUsage | AI credit consumption and schedule for increases. |
automation_runs | AutomationRunsUsage | Execution count for automations. |
domains | DomainsUsage | Created domains vs maximum allowed. |
rate_limit | UsageRateLimit | Current requests allowed per specific duration. |
Sources: src/usage.rs:26-45
Email Usage Periods
Email usage is tracked via EmailUsagePeriod, which identifies volume and reset times.
This diagram shows the relationship between the top-level usage object and the granular email period data.
Sources: src/usage.rs:29-64
Logs API
The LogsSvc interacts with the /logs endpoints to provide transparency into API interactions. It supports fetching a single log entry by ID or listing multiple logs with pagination.
Sources: src/logs.rs:12-13
Log Data Model
Each Log object represents a single HTTP request made to the Resend API.
| Field | Type | Description |
|---|---|---|
id | LogId | Unique identifier for the log entry. |
endpoint | String | The API path targeted by the request. |
method | String | HTTP method (e.g., GET, POST). |
response_status | NonZeroU16 | HTTP status code returned by the server. |
request_body | Value | The JSON payload sent in the request. |
response_body | Value | The JSON payload returned in the response. |
Sources: src/logs.rs:47-60
Request Flow for Logs
When you request logs, the service builds a GET request using the shared configuration.
The diagram illustrates the internal flow from the service call to the final parsed response.
Sources: src/logs.rs:34-42, src/config.rs:118-125
Service Integration
Both services are accessible through the main Resend client via the usage and logs fields. They share a common Arc<Config> which handles authentication, base URLs, and internal rate limiting.
Sources: src/lib.rs:125-132, src/config.rs:93-100
Configuration & Rate Limits
By default, the client limits outgoing requests to 9 per 1.1 seconds to stay within the standard 10 requests per second limit. If the server returns a 429 status, the client parses the ratelimit-limit, ratelimit-remaining, and ratelimit-reset headers into an Error::RateLimit.
Sources: src/config.rs:112-116, src/config.rs:141-158, src/lib.rs:12-17
Implementation Example
Retrieving account usage:
let resend = Resend::default();
let usage = resend.usage.get().await?;
println!("Daily emails used: {}", usage.emails.daily.used);
Sources: src/usage.rs:15-22, src/lib.rs:35-51
The Usage and Logs APIs allow developers to build monitoring tools and audit trails directly into their Rust applications using the resend-rs SDK.