> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.brevo.com/guides/rust/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.brevo.com/_mcp/server.
# Rust SDK
## Overview
The Brevo Rust SDK (`brevo-rust`) is a typed client library for the Brevo API. It provides:
* A unified `BrevoClient` with one namespaced client per API area, such as `transactional_emails` and `contacts`
* Typed request and response structs
* A typed `ApiError` for every documented error status
* Automatic retries with exponential backoff
* Per-request overrides through `RequestOptions`
* A custom `reqwest` client option for proxies and TLS settings
[](https://crates.io/crates/brevo-rust)
## Requirements
* Rust 2021 edition
* An async runtime such as [`tokio`](https://tokio.rs), which the examples use
The SDK uses [`reqwest`](https://docs.rs/reqwest) with `rustls` for TLS, so it needs no system OpenSSL.
## Installation
```bash
cargo add brevo-rust
```
Import the crate as `brevo_rust`:
```rust
use brevo_rust::prelude::*;
```
## Authentication
The Rust SDK authenticates with your Brevo [API key](/docs/api-key-authentication), which it sends in the `api-key` request header. OAuth 2.0 machine-to-machine authentication is not supported in the Rust SDK yet; use an API key.
```rust
use brevo_rust::prelude::*;
let config = ClientConfig {
api_key: Some(std::env::var("BREVO_API_KEY").expect("BREVO_API_KEY not set")),
..Default::default()
};
let client = BrevoClient::new(config).expect("Failed to build client");
```
You can override the key for a single call with `RequestOptions::new().api_key("...")`.
## Quick start
Initialize the client and send your first email:
**`src/main.rs`**
```rust title="src/main.rs"
use brevo_rust::prelude::*;
#[tokio::main]
async fn main() {
let config = ClientConfig {
api_key: Some("your-api-key".to_string()),
..Default::default()
};
let client = BrevoClient::new(config).expect("Failed to build client");
let result = client
.transactional_emails
.send_transac_email(
&SendTransacEmailRequest {
subject: Some("Hello from Brevo!".to_string()),
html_content: Some(
"
Hello,
This is my first transactional email.
"
.to_string(),
),
sender: Some(SendTransacEmailRequestSender {
name: Some("Alex from Brevo".to_string()),
email: Some("hello@brevo.com".to_string()),
..Default::default()
}),
to: Some(vec![SendTransacEmailRequestToItem {
email: "johndoe@example.com".to_string(),
name: Some("John Doe".to_string()),
..Default::default()
}]),
..Default::default()
},
None,
)
.await;
match result {
Ok(response) => println!("Sent: {:?}", response),
Err(ApiError::UnauthorizedError { message, .. }) => eprintln!("Check your API key: {message}"),
Err(ApiError::TooManyRequestsError { message, .. }) => eprintln!("Rate limited: {message}"),
Err(e) => eprintln!("Request failed: {e}"),
}
}
```
Every method takes a request struct (when the endpoint has a body or parameters) and an `Option`, and returns `Result`. Request structs implement `Default`, so you set only the fields you need.
## Configuration
`ClientConfig` configures the client. Build one directly, as in the examples above, or use `ApiClientBuilder`:
```rust
use brevo_rust::ApiClientBuilder;
use std::time::Duration;
let client = ApiClientBuilder::new("https://api.brevo.com/v3")
.api_key("your-api-key")
.timeout(Duration::from_secs(30))
.max_retries(5)
.build()
.expect("Failed to build client");
```
### Client configuration fields
| Field | Type | Default | Description |
| ---------------- | ------------------------- | -------------------------- | ------------------------------------------------------------------------- |
| `api_key` | `Option` | `None` | Your Brevo API key |
| `base_url` | `String` | `https://api.brevo.com/v3` | API base URL |
| `timeout` | `Duration` | 60 seconds | Default request timeout |
| `max_retries` | `u32` | `3` | Default number of retries |
| `custom_headers` | `HashMap` | SDK identification headers | Extra headers sent with every request |
| `user_agent` | `String` | `brevo-rust/` | `User-Agent` header |
| `reqwest_client` | `Option` | `None` | Your own `reqwest` client (see [Custom HTTP client](#custom-http-client)) |
`ClientConfig` also has fields for other credential types. They are not used by this SDK yet; authenticate with `api_key`.
## Error handling
Every method returns `Result`. Match on the variants you care about and handle the rest with a catch-all arm, as in the quick start.
### Error variants
| Variant | When it happens |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `BadRequestError`, `UnauthorizedError`, `PaymentRequiredError`, `ForbiddenError`, `NotFoundError`, `MethodNotAllowedError`, `ConflictError`, `PreconditionFailedError`, `UnsupportedMediaTypeError`, `ExpectationFailedError`, `UnprocessableEntityError`, `FailedDependencyError`, `TooEarlyError`, `TooManyRequestsError`, `InternalServerError` | The API returned the corresponding HTTP error status. Each carries the API's `message` and any extra fields it documents. |
| `Http { status, message }` | The API returned an error status that has no dedicated variant |
| `Network` | The request failed before a response arrived (connection or timeout error) |
| `Serialization` | A request or response body could not be converted to or from JSON |
| `Configuration` | The client was built with an invalid configuration |
| `InvalidHeader` | A header value was not valid |
The full list is in the crate's `error.rs`, on [docs.rs](https://docs.rs/brevo-rust).
## Retries
The SDK retries failed requests automatically, up to 3 times by default. It retries when:
* The API returns `408`, `429`, or any status `500` or above
* The request fails with a network error
The wait between attempts doubles each time, starting at 100 ms. Any other status, such as `400` or `404`, is returned immediately without retrying. Set the number of retries on the client with `max_retries`, or for a single call with `RequestOptions`:
```rust
let response = client
.transactional_emails
.send_transac_email(&request, Some(RequestOptions::new().max_retries(5)))
.await;
```
Set `max_retries` to `0` to turn retries off.
## Timeouts
Requests time out after 60 seconds by default. Change the default on the client with `timeout`, or for a single call:
```rust
let response = client
.transactional_emails
.send_transac_email(&request, Some(RequestOptions::new().timeout_seconds(30)))
.await;
```
## Request options
`RequestOptions` customizes a single call. Besides `max_retries` and `timeout_seconds`, you can:
```rust
let options = RequestOptions::new()
.api_key("another-api-key")
.additional_header("X-My-Header", "value")
.additional_query_param("debug", "true");
```
`additional_body_param` adds a property to the request body in the same way.
## Custom HTTP client
Provide your own `reqwest::Client` to control proxies, TLS roots or connection settings. When set, it owns all transport-level configuration:
```rust
use brevo_rust::ApiClientBuilder;
let http = reqwest::Client::builder().build().expect("reqwest client");
let client = ApiClientBuilder::new("https://api.brevo.com/v3")
.api_key("your-api-key")
.reqwest_client(http)
.build()
.expect("Failed to build client");
```
## Available services
`BrevoClient` exposes the following service namespaces:
| Property | Description |
| ------------------------- | ----------------------------------------------------------- |
| `transactional_emails` | Send emails, manage templates, blocked contacts and domains |
| `transactional_sms` | Send SMS messages and view delivery statistics |
| `transactional_whats_app` | Send WhatsApp messages and view event reports |
| `sms_templates` | List SMS templates |
| `contacts` | Manage contacts, lists, folders, attributes and segments |
| `consent_groups` | Manage consent groups |
| `email_campaigns` | Create and manage email marketing campaigns |
| `sms_campaigns` | Create and manage SMS marketing campaigns |
| `whats_app_campaigns` | Create and manage WhatsApp campaigns and templates |
| `companies` | Manage CRM companies |
| `deals` | Manage CRM deals and pipelines |
| `tasks` | Manage CRM tasks |
| `notes` | Manage CRM notes |
| `files` | Upload and manage CRM files |
| `conversations` | Manage conversation messages and automated messages |
| `ecommerce` | Manage products, categories, orders and attribution |
| `coupons` | Manage coupon collections and coupons |
| `payments` | Create and manage payment requests |
| `event` | Track custom events |
| `webhooks` | Manage webhooks |
| `senders` | Manage senders and IPs |
| `domains` | Manage and authenticate domains |
| `account` | Retrieve account information and activity logs |
| `inbound_parsing` | Retrieve inbound email events and attachments |
| `custom_objects` | Manage custom object records |
| `external_feeds` | Manage external RSS feeds |
| `master_account` | Manage sub-accounts and groups (enterprise) |
| `user` | Manage users and permissions |
| `process` | Retrieve background process status |
| `program` | Manage loyalty programs |
| `balance` | Manage loyalty balances and transactions |
| `reward` | Manage loyalty rewards and vouchers |
| `tier` | Manage loyalty tiers and tier groups |
| `wallet` | Get wallet pass install URLs and redeem wallet passes |
Every method and its request and response types are listed in the [reference](https://github.com/getbrevo/brevo-rust/blob/main/reference.md).
## Resources
* [GitHub Repository](https://github.com/getbrevo/brevo-rust)
* [crates.io Package](https://crates.io/crates/brevo-rust)
* [docs.rs documentation](https://docs.rs/brevo-rust)
* [API Reference](https://developers.brevo.com/reference)
* [Support](mailto:support@brevo.com)
> Learn how to integrate the Brevo API into your Rust applications.
## Docs
- [Rust SDK Changelog](https://developers.brevo.com/guides/rust/changelog.md): Release history for the brevo-rust SDK.