Skip to main content
The Client is the main entry point for interacting with the Resend API. It manages authentication, HTTP communication, and provides access to all service endpoints.

Client Structure

The Client struct contains all the service interfaces for interacting with different Resend API endpoints:
*EmailsSvcImpl
Service for sending, retrieving, and managing emails
BatchSvc
Service for sending batch emails
ApiKeysSvc
Service for managing API keys
DomainsSvc
Service for managing domains
SegmentsSvc
Service for managing audience segments
*ContactsSvcImpl
Service for managing contacts
BroadcastsSvc
Service for managing broadcasts
TemplatesSvc
Service for managing email templates
TopicsSvc
Service for managing topics
WebhooksSvc
Service for managing webhooks
string
The API key used for authentication
*url.URL
The base URL for API requests (defaults to https://api.resend.com/)
string
The user agent string sent with requests

Constructors

NewClient

Creates a new Resend client with default configuration.
string
required
Your Resend API key. The function automatically trims whitespace and quotes.
*Client
A configured Resend client instance ready to use
Example

NewCustomClient

Creates a new Resend client with a custom HTTP client. Use this constructor when you need to configure specific HTTP settings like timeouts, proxies, or custom transports.
*http.Client
Custom HTTP client for making requests. If nil, uses the default client with a 1-minute timeout.
string
required
Your Resend API key
*Client
A configured Resend client instance with custom HTTP settings
Example

Configuration

Base URL

The base URL for API requests can be configured using the RESEND_BASE_URL environment variable. This is useful for testing or when using a proxy. Default: https://api.resend.com/ Example

HTTP Client Configuration

The default HTTP client has a 1-minute timeout. You can customize this using NewCustomClient:

Context Support

All API methods in the Resend Go SDK support context for cancellation, timeouts, and passing request-scoped values. Example with timeout
Example with cancellation

User Agent

The SDK automatically sets a user agent header in the format resend-go/{version}. The current version is 3.1.1.

Error Handling

The client automatically handles errors from the API and returns appropriate error types:
  • Rate Limit Errors: RateLimitError with retry information
  • Invalid Request Errors: Standard errors for validation failures
  • Other Errors: Generic errors with message from the API

Next Steps

Send Emails

Learn how to send emails using the SDK

Batch Emails

Send multiple emails in a single request

Manage Domains

Configure and verify your sending domains

Email Templates

Create and manage email templates