Node.js SDK
Overview
The Brevo Node.js SDK (@getbrevo/brevo) is a TypeScript-first client library for the Brevo API. It provides:
- A unified
BrevoClientwith namespaced service clients - Full TypeScript types with IDE autocomplete
- Promise-based async/await API
- Automatic retries with exponential backoff
- Custom fetch support for any runtime
- Structured error handling with typed error classes
Version 4.0 is a full rewrite and is not backwards compatible with the v3.x SDK. The legacy v3.x SDK (@getbrevo/brevo@^3.0.1) will continue to receive critical security updates but no new features. We recommend migrating to v4.x for new and existing projects.
Requirements
- Node.js 18+
- Also compatible with: Vercel, Cloudflare Workers, Deno v1.25+, Bun 1.0+, React Native
Installation
Quick start
Initialize the client and send your first email:
Configuration
Pass options to the constructor to configure timeout, retries, and other settings:
Constructor options
Error handling
The SDK throws typed error classes based on HTTP status codes:
Error classes
All BrevoError instances expose:
statusCode— HTTP status codemessage— Error messagebody— Parsed response bodyrawResponse— Raw response with headers
Retries
Automatic retries with exponential backoff are enabled by default (2 retries). Configure at the client or request level:
Retry behavior
- Retryable status codes:
408,429,500,502,503,504 - Backoff schedule: ~1s, ~2s, ~4s (exponential with jitter)
- Rate limit headers: Respects
Retry-Afterresponse header
Timeouts
Default timeout is 60 seconds. Configure at the client or request level:
Recommended timeout values
Request options
All service methods accept a request options object as the final argument:
Abort signal
Cancel in-flight requests using the Web AbortController API:
Raw response
Access response headers and metadata via .withRawResponse():
Binary responses
Endpoints that return binary content (e.g., attachment downloads) expose multiple consumption methods:
Saving binary content
Node.js (ReadableStream)
Bun
Browser
TypeScript types
All request and response types are exported from the package:
Logging
Configure logging to inspect outgoing requests and responses:
Custom logger
Integrate with any logging library by implementing the ILogger interface:
Custom fetch
Override the default fetch implementation for any runtime or to add request interceptors:
Common integrations
node-fetch
undici
With request ID header
Available services
The BrevoClient exposes the following service namespaces: