How-To

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 HussainSohail Hussain7 min read

Short 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:

  1. 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.
  2. You set ssl: [verify: :verify_peer] yourself and left out cacerts.
  3. 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.
  4. Another dependency pins an old hackney, so mix deps.update seems 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

  1. Open mix.lock and note the current hackney and httpoison versions.
  2. Run mix deps.update httpoison hackney.
  3. If hackney does not move, run mix deps.tree and find which dependency pins it.
  4. Recompile, then repeat the Brevo call without any ssl option in your code.
  5. 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:

  1. Install the OS package in your image (ca-certificates on Debian, Ubuntu and Alpine). I'd do this; the system store also receives security updates.
  2. Bundle a store through a dependency. With certifi, use cacerts: :certifi.cacerts(). With castore, use cacertfile: CAStore.file_path() in place of cacerts.

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 seeLikely causeFix
The exact :options, :incompatible error and no ssl option in your codeHackney path that supplies no CA list on OTP 26Update deps, then Fix 2
Same error, and you set verify: :verify_peer yourselfverify set without cacertsAdd cacerts and keep exactly one CA source
Works locally, fails in Docker or CIDifferent OTP, or no CA certificates in the imageCheck OTP in that environment; install ca-certificates
Certificate or TLS alert after adding cacertsOutdated CA store, or a proxy that re-signs trafficRefresh the image or bundle certifi/castore
Hostname mismatch errorYou 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 goneWrong or restricted api-keyCheck 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 ssl options 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.

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.

strategybrevoerror-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

Building Mailneo — AI-powered email marketing for growing businesses.

Ready to supercharge your email marketing?

Start sending smarter emails with AI-powered campaigns. No credit card required.

Get Started Free