Rust SDK
Overview
The Brevo Rust SDK (brevo-rust) is a typed client library for the Brevo API. It provides:
- A unified
BrevoClientwith one namespaced client per API area, such astransactional_emailsandcontacts - Typed request and response structs
- A typed
ApiErrorfor every documented error status - Automatic retries with exponential backoff
- Per-request overrides through
RequestOptions - A custom
reqwestclient option for proxies and TLS settings
Requirements
- Rust 2021 edition
- An async runtime such as
tokio, which the examples use
The SDK uses reqwest with rustls for TLS, so it needs no system OpenSSL.
Installation
Import the crate as brevo_rust:
Authentication
The Rust SDK authenticates with your Brevo API key, 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.
You can override the key for a single call with RequestOptions::new().api_key("...").
Quick start
Initialize the client and send your first email:
Every method takes a request struct (when the endpoint has a body or parameters) and an Option<RequestOptions>, and returns Result<T, ApiError>. 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:
Client configuration fields
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<T, ApiError>. Match on the variants you care about and handle the rest with a catch-all arm, as in the quick start.
Error variants
The full list is in the crate’s error.rs, on docs.rs.
Retries
The SDK retries failed requests automatically, up to 3 times by default. It retries when:
- The API returns
408,429, or any status500or 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:
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:
Request options
RequestOptions customizes a single call. Besides max_retries and timeout_seconds, you can:
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:
Available services
BrevoClient exposes the following service namespaces:
Every method and its request and response types are listed in the reference.