Node.js SDK
Overview
The Brevo Node.js SDK provides a TypeScript-first client library for interacting with the Brevo API. It offers type-safe methods, automatic retries, and comprehensive error handling.
Version 4.0 
Version 4.0 of the Node.js SDK has been released with significant improvements:
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 projects and existing applications.
- Promise-based API with async/await support
- Enhanced TypeScript types and autocomplete
- Standardized error handling with specific error types
- Improved retry logic with exponential backoff
- Better timeout configuration
- Support for custom fetch implementations
- Binary response handling
Installation
Install the SDK using npm:
Quick start
Initialize the client and send your first email:
Configuration
Configure the client with custom timeout and retry settings:
Error handling
The SDK throws specific error types based on HTTP status codes. Handle errors appropriately:
Error types
The SDK provides the following error types:
400-BadRequestError401-UnauthorizedError403-ForbiddenError404-NotFoundError422-UnprocessableEntityError429-TooManyRequestsError500+-InternalServerError
All BrevoError instances provide:
statusCode: HTTP status codemessage: Error messagebody: Parsed error response bodyrawResponse: Raw response with headers
Retries
Automatic retries with exponential backoff are enabled by default (2 retries). Configure retries at the client or request level:
Retry behavior
- Retryable status codes:
408,429,500,502,503,504 - Exponential backoff: ~1s, ~2s, ~4s (with jitter)
- Respects
Retry-Afterheader for rate limits - Can be disabled per request with
maxRetries: 0
Timeouts
Default timeout is 60 seconds. Configure at client or request level:
Recommended timeout values
- Standard API calls:
30-60s(default) - Quick operations:
10-15s - Bulk operations:
120-300s - Real-time:
5-10s
Request options
Additional headers
Add custom headers to requests:
Query parameters
Add query parameters to requests:
Abort signal
Cancel requests using AbortController:
Raw response
Access raw response headers and metadata:
Binary responses
Handle binary responses from endpoints like attachment downloads:
Saving binary responses
Node.js (ReadableStream)
Save binary responses to a file in Node.js:
Bun
Save binary responses to a file in Bun:
Browser
Download binary responses in the browser:
TypeScript types
All request and response types are exported for use in your application:
Logging
Configure logging to debug API calls:
Custom logger
Implement a custom logger using your preferred logging library:
Custom fetch client
Override the default fetch implementation for advanced use cases:
Common use cases
Using node-fetch
Use node-fetch as the fetch implementation:
Using undici
Use undici’s fetch implementation:
With interceptors
Add request interceptors for custom headers or logging:
Runtime compatibility
The SDK is compatible with:
- Node.js 18+
- Vercel
- Cloudflare Workers
- Deno v1.25+
- Bun 1.0+
- React Native
Migration from v3.x
Version 4.0.1 includes breaking changes. Follow this guide to migrate from v3.x:
Key changes
- New client initialization
- Promise-based API
- Improved TypeScript support
- Standardized error handling