HTTPoison options incompatible: cacerts undefined on OTP 26
On OTP 26, Erlang's ssl client verifies server certificates by default but won't guess a CA list. If your HTTP client ends up with verify_peer and no cacerts, the call fails with this error. Pass the OS trust store to HTTPoison with :public_key.cacerts_get(), or upgrade hackney and HTTPoison.
Sohail Hussain7 min readShort answer
- OTP 26 turned certificate verification on by default, so your request reached Erlang's ssl with verify_peer but no list of trusted CA certificates.
- Pass ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get(), customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]] to HTTPoison. Updating hackney and HTTPoison first is worth a try.
- Do not use verify: :verify_none, because your Brevo api-key header would then go to a server nobody verified.
After upgrading Erlang/OTP to 26, your Brevo API v3 call (or any HTTPS call) returns this:
%HTTPoison.Error{reason: {:options, :incompatible, [verify: :verify_peer, cacerts: :undefined]}, id: nil}
The request never reached Brevo. The TLS client refused to start because it was told to verify the server certificate but was given nothing to verify it against. This is an Elixir/Erlang TLS problem, not a Brevo outage or a bad API key.
Why it happens
Erlang's ssl application changed its client defaults in OTP 26: peer verification is now on unless you turn it off. When verify: :verify_peer is set and neither cacerts nor cacertfile is supplied, ssl rejects the option set as incompatible. That is the tuple you see.
Causes, most common first:
- An older hackney (or a library that wraps it) builds SSL options without a CA list. HTTPoison is a thin wrapper over hackney, and hackney assembles the final options. Your own code may set no SSL option at all and still hit this. Users report exactly this pattern with a Brevo integration after an OTP upgrade.
- You set
ssl: [verify: :verify_peer]yourself and left outcacerts. - The release image runs a different OTP than your laptop. The error shows up only in the container or CI that picked up the new OTP.
- Another dependency pins an old hackney, so
mix deps.updateseems to do nothing. Mail libraries such as Swoosh or HTTP wrappers such as Tesla can do this.
I could not verify which hackney release first handles the OTP 26 defaults, so I won't name one. The reliable test is to update and retry, as in Fix 1. Fix 2 works whatever version you end up on.
Fix 1: update hackney and HTTPoison, then retest
- Open
mix.lockand note the currenthackneyandhttpoisonversions. - Run
mix deps.update httpoison hackney. - If hackney does not move, run
mix deps.treeand find which dependency pins it. - Recompile, then repeat the Brevo call without any
ssloption in your code. - If it now returns an HTTP status (even a 401), TLS is fixed and you can stop. If the same error comes back, go to Fix 2.
Fix 2: pass the CA list in the request options
HTTPoison hands its ssl option to hackney. This module sends a transactional email through Brevo's v3 endpoint with explicit TLS options:
defmodule MyApp.Brevo do
@url "https://api.brevo.com/v3/smtp/email"
def send_email(to, subject, html) do
body =
Jason.encode!(%{
sender: %{name: "My App", email: "hello@example.com"},
to: [%{email: to}],
subject: subject,
htmlContent: html
})
headers = [
{"api-key", System.fetch_env!("BREVO_API_KEY")},
{"content-type", "application/json"},
{"accept", "application/json"}
]
HTTPoison.post(@url, body, headers, ssl: ssl_options())
end
defp ssl_options do
[
verify: :verify_peer,
cacerts: :public_key.cacerts_get(),
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
]
end
end
:public_key.cacerts_get/0 loads the operating system's trust store and exists from OTP 25 onward, so you can ship this before upgrading to 26. The customize_hostname_check option makes the hostname check explicit with the same matching rules HTTPS uses, so the certificate must match the host you called (api.brevo.com).
Keep the API key in an environment variable, as above, rather than in source code. A key with restricted permissions would fail later with an HTTP error, not with this TLS error.
Do not turn verification off
Many answers online suggest ssl: [verify: :verify_none]. It silences the error because nothing is verified any more, so anyone on the network path could impersonate Brevo and read your api-key header. Skip it, even in staging.
When cacerts_get fails
:public_key.cacerts_get() needs CA certificates on the operating system. Slim Docker images, Alpine without ca-certificates, and some distroless bases don't ship them. You will see an error from public_key, or a certificate verification failure on the first request.
Two ways out:
- Install the OS package in your image (
ca-certificateson Debian, Ubuntu and Alpine). I'd do this; the system store also receives security updates. - Bundle a store through a dependency. With certifi, use
cacerts: :certifi.cacerts(). With castore, usecacertfile: CAStore.file_path()in place ofcacerts.
Use one source of CA certificates, not several.
Which problem do you have
The table doubles as a checklist: each row is a condition that should be true before you retry.
| What you see | Likely cause | Fix |
|---|---|---|
The exact :options, :incompatible error and no ssl option in your code | Hackney path that supplies no CA list on OTP 26 | Update deps, then Fix 2 |
Same error, and you set verify: :verify_peer yourself | verify set without cacerts | Add cacerts and keep exactly one CA source |
| Works locally, fails in Docker or CI | Different OTP, or no CA certificates in the image | Check OTP in that environment; install ca-certificates |
Certificate or TLS alert after adding cacerts | Outdated CA store, or a proxy that re-signs traffic | Refresh the image or bundle certifi/castore |
| Hostname mismatch error | You are connecting to something other than api.brevo.com (proxy, IP address, typo) | Use https://api.brevo.com/v3/smtp/email with no host rewriting |
| HTTP 401 after the TLS error is gone | Wrong or restricted api-key | Check the key in your Brevo account |
To confirm which OTP you actually run, execute this in the same environment as your app (a release image may carry a different OTP than your laptop):
erl -noshell -eval 'io:format("~s~n", [erlang:system_info(otp_release)]), halt().'
Also search your code for verify_none; it should appear nowhere.
Keep the fix in one place
If your app calls several HTTPS APIs, keep the SSL options in one function, as in the module above, so the next OTP change needs one edit. Clients built on Mint, such as Finch or Req, are another route; switching clients is a bigger change than this bug deserves unless you were planning it. If you send through a library like Swoosh, find out which HTTP client it uses, because that client is the one that needs the options.
If nothing works
Brevo support can't help until a request actually reaches Brevo and gets an HTTP response. Take the problem to the hackney project's issue tracker or the Elixir community, and include:
- Your OTP release and Elixir version.
- The output of
mix deps | grep -E "hackney|httpoison|certifi". - Whether you run in a container, and its base image.
- The full error tuple and the
ssloptions you pass, with the API key removed.
After upgrading to OTP {version}, HTTPoison calls to https://api.brevo.com/v3/smtp/email fail with:
%HTTPoison.Error{reason: {:options, :incompatible, [verify: :verify_peer, cacerts: :undefined]}, id: nil}
Versions: Elixir {x.y}, hackney {x.y.z}, httpoison {x.y.z}, certifi {x.y.z}
Runtime: {Docker base image or host OS}
Already tried: deps.update, ssl: [verify: :verify_peer, cacerts: :public_key.cacerts_get()]
Result of the last attempt: {error text}
Common questions
Does this affect other HTTPS APIs, not just Brevo?
Yes. Any HTTPoison or hackney call to an HTTPS endpoint can hit it on OTP 26, because the failure happens in the TLS client before the request is sent. Brevo is just where the original report appeared.
Can I stay on OTP 25 instead?
You can, and the error would not appear, but that only postpones the change. Passing explicit CA certificates works on OTP 25 as well, so you can add the fix first and upgrade later.
Why does cacerts_get work on my laptop but not in Docker?
Your laptop has a system CA store; many minimal images do not. Install ca-certificates in the image, or bundle certifi or castore.
Is a 401 from Brevo related to this error?
No. A 401 means the TLS handshake succeeded and Brevo rejected the api-key. At that point, check the key and its permissions in your Brevo account.
Explore: Email Marketing Strategy
Related Articles
414 Request-URI Too Large in n8n's Amazon SES node: fix
The error 414 Request-URI Too Large in n8n's AWS SES node means a server in the path refused a request whose URL was too long, which a long HTML body can cause when it travels in the URL. Send through the SES v2 API with an HTTP Request node, or use SES SMTP.
Access denied, bad outbound sender: Outlook cold email fix
"Access denied, bad outbound sender" (550 5.1.8) means Microsoft 365 has put your mailbox on its restricted users list for spam-like sending. An admin must unblock it under Restricted entities in the Microsoft Defender portal. Then clean your list, lower your volume and resume gradually.
Acoustic Campaign "Application error" on login: bookmark fix
Acoustic Campaign shows "application error" at login when you open it from a bookmark saved while you were logged in, because the bookmark carries the old session. Log out, type your pod URL (campaign-us-[X].goacoustic.com) into the address bar, log in, then save a fresh bookmark.
ActiveCampaign 502 Bad Gateway and Tags Failed to Load: Fixes
"Bad gateway Error code 502" in ActiveCampaign means Cloudflare, the proxy in front of the app, got no valid response from ActiveCampaign's servers. That is usually their side. Check the status page, retry in a clean browser session, clear cookies, then send support the Ray ID if it persists.
Ready to supercharge your email marketing?
Start sending smarter emails with AI-powered campaigns. No credit card required.
Get Started Free