Installation & Setup
Relevant source files
The following files were used as context for generating this wiki page:
Installation & Setup covers the process of adding the Resend Go SDK to a project and configuring the client to interact with the Resend API. This module enables developers to authenticate requests, manage service-specific clients, and configure global options such as pagination and idempotency.
The SDK requires a valid API key obtained from the Resend Dashboard and supports Go environments compatible with version 4 of the library.
Installation
You install the Resend Go SDK using the standard Go package manager. This adds the library to your go.mod file and makes the resend package available for import.
go get github.com/resend/resend-go/v4
Sources: README.md:15-17
Client Initialization
To interact with Resend services, you must initialize a Client object. The NewClient function accepts a string representing your API key. It is common practice to retrieve this key from an environment variable for security.
apiKey := os.Getenv("RESEND_API_KEY")
client := resend.NewClient(apiKey)
Sources: examples/send_email.go:14-18, examples/automations.go:14-17
Architecture Overview
The SDK follows a service-based architecture where the main Client provides access to specific sub-services like Emails, Topics, and Automations.
The diagram shows the hierarchical relationship between the main Client and the specialized service implementations. Sources: README.md:27-44, topics.go:56-60, CHANGELOG.md:15-25
Authentication and Security
Requests to the Resend API require an API key for authentication. For webhook reception, the SDK also provides verification utilities that require a Webhook Secret.
| Element | Source | Purpose |
|---|---|---|
| API Key | os.Getenv("RESEND_API_KEY") | Authenticates outgoing requests to Resend API. |
| Webhook Secret | Manual Configuration | Validates HMAC-SHA256 signatures for incoming webhooks. |
| Idempotency Key | SendEmailOptions | Prevents duplicate processing of the same request within 24 hours. |
Sources: examples/send_email.go:39-41, examples/webhook_receiver.go:16-17
Global Configuration
Pagination Support
Most listing operations support pagination via the ListOptions structure. You control the data volume and position using Limit, After, and Before parameters.
The flow diagram illustrates the cursor-based pagination logic used throughout the SDK. Sources: examples/with_pagination.go:23-35, topics.go:101-105
List Options Parameters
| Parameter | Type | Description |
|---|---|---|
Limit | *int | Number of records to return (e.g., default 20). |
After | *string | Cursor for fetching the next page of results. |
Before | *string | Cursor for fetching the previous page of results. |
Sources: examples/with_pagination.go:24-60, topics.go:52-54
Context Management
Every service method provides a WithContext variant (e.g., CreateWithContext). You should use these variants to pass a context.Context, allowing for request cancellation, timeouts, and tracing in production environments.
ctx := context.TODO()
resp, err := client.Topics.CreateWithContext(ctx, params)
Sources: topics.go:62-65, examples/automations.go:14-22
Summary
Setting up the Resend Go SDK involves installing the v4 package and initializing a central Client with an API key. The system uses a modular service architecture, allowing you to access features like email delivery and contact management through specialized service attributes on the client. Proper setup includes handling environment-based authentication and implementing cursor-based pagination for large datasets.