Skip to main content
The Elixir SDK provides a typed client for the Surge API plus a Phoenix-friendly WebhookPlug and WebhookHandler behaviour for handling inbound events. It’s published as surge_api on Hex and supports Elixir 1.14 and newer. This page covers installing the package, configuring the client for Phoenix, sending your first request, handling errors, and wiring webhook routes with either the plug or the behaviour.

Install and authenticate

Add to your mix.exs:
mix.exs
Set your API key in config:
config/runtime.exs
Or create a client directly:

Your first request

Using the default client (reads from application config):
Or with an explicit client:

Retrieving a message

Error handling

The SDK returns tagged tuples:

Webhook handling

WebhookPlug for Phoenix

The SDK includes Surge.WebhookPlug that handles signature verification and event parsing. Add it to your endpoint.ex before Plug.Parsers:
lib/my_app_web/endpoint.ex
For runtime configuration, pass a tuple or function as the secret:

WebhookHandler behaviour

Implement the Surge.WebhookHandler behaviour to process events. The callback receives a Surge.Events.Event struct with an atom type and a data field:
The callback should return :ok or {:ok, term} for success, or :error or {:error, reason} to signal a failure (which returns HTTP 400 to Surge).

Manual signature verification

The Elixir SDK currently consumes the older surge-signature header (format t=<ts>,v1=<hex>) with a different signed-payload composition than the Standard Webhooks spec used by Python / TypeScript / Ruby. Migrating to Standard Webhooks (webhook-signature) this week — this Note will be removed once the migration ships. See Signature validation for both formats.
If you’re not using Surge.WebhookPlug, verify signatures with Surge.Webhook.construct_event/3:
The signature_header is the value of the surge-signature HTTP header, formatted as t=timestamp,v1=hex_signature.