Generate your own client from the OpenAPI document

exx.sh ships SDKs for TypeScript, Python, Go and Rust. For any other language, or to own your client end to end, generate one from the API's OpenAPI document. This guide covers where the document lives, what is in it, how to generate a client with common tools, and how to keep that client correct as the API grows.

Get the document

The API serves its own description, no key needed:

curl -sS https://api.exx.sh/openapi.json -o exx-openapi.json

The document is generated from the server's code, so it always describes the API that answers at that host. Answers are cached for five minutes (Cache-Control: public, max-age=300). It is OpenAPI 3.1; some generators read only 3.0 (see below).

What the document says

TopicIn the documentWhat your client must do
Authenticationcomponents.securitySchemes.bearerSend Authorization: Bearer <API key> on every call
OperationsOne operationId per operation (send_email, list_domains, ...), grouped by tagsMap each to a method; the id is stable, the path may not be the best name
Errors4XX and 5XX answers with the ErrorBody schema: { statusCode, name, message }Branch on name, not on message; any status can carry an envelope
Paginationlimit, after and before query parameters on list operationsPass the last id of a page as after to get the next one (suppressions page by address)
IdempotencyIdempotency-Key header on send_email and send_batchSend one key per logical email and reuse it on every retry of that email
Sending streamX-Exx-Stream header (transactional or distributional) on the sendsOptional; transactional is the default
Rate limits429 with Retry-After and ratelimit-* headersWait Retry-After seconds before trying again

Fields are snake_case on the wire, as in Resend's API.

Generate a client

Point any generator at the downloaded file. These are the generators and settings the official SDKs use.

TypeScript: Hey API

npx @hey-api/openapi-ts -i exx-openapi.json -o src/exx \
  -p @hey-api/client-fetch @hey-api/typescript @hey-api/sdk

Set auth to the API key and baseUrl to https://api.exx.sh when you create the client.

Python: openapi-python-client

uvx openapi-python-client generate --path exx-openapi.json --meta none \
  --output-path exx_client

Use literal_enums: true in a config file (--config) to get Literal types instead of enum classes. Build the client with AuthenticatedClient(base_url=..., token=<API key>).

Go: oapi-codegen

# oapi-codegen.yaml
package: exxapi
output: exxapi.gen.go
generate:
  models: true
  client: true
go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest \
  -config oapi-codegen.yaml exx-openapi.json

Use the ClientWithResponses it generates: it decodes JSON4XX and JSON5XX into ErrorBody for you. Add the bearer header with a request editor.

Rust: progenitor

progenitor reads OpenAPI 3.0 only. Lower the document first: turn "type": ["string", "null"] into "type": "string", "nullable": true, oneOf: [X, {"type": "null"}] into allOf: [X] plus nullable, const into a one-value enum, and set "openapi": "3.0.3". Then generate with progenitor::Generator from a build.rs or a small binary.

Other languages

openapi-generator (Java, Kotlin, C#, PHP, Ruby, Swift, Dart, ...) and Kiota (C#, Java, PHP, Ruby, Swift, ...) both read the document. If your generator rejects 3.1, lower it to 3.0 as described for Rust.

What a generated client does not do

Generators turn operations into calls. The official SDKs add these behaviours on top, and you will want them too:

  1. Idempotent sends. Make a key per email (a UUID, or your own id such as order-123/receipt) and send it as Idempotency-Key. The same key with the same body returns the first answer; with another body it is refused (409 invalid_idempotent_request).
  2. Retries. Retry 429 after Retry-After, except daily_quota_exceeded and monthly_quota_exceeded, which do not clear in seconds. Retry 500, 502, 503, 504 and lost connections only when a second try cannot act twice: reads, deletes, and sends that carry an Idempotency-Key. Retry 409 concurrent_idempotent_requests: the server is still working on that key. Back off exponentially and cap the wait.
  3. Timeouts per attempt, so a retry gets its own time.
  4. Webhook verification. Events are signed with the Standard Webhooks scheme: HMAC-SHA256 over {svix-id}.{svix-timestamp}.{raw body} with the base64 key after whsec_, compared in constant time against each v1, signature in svix-signature, with a five-minute tolerance on the timestamp. Refuse an empty secret.
  5. Errors that never lose the name. Read ErrorBody from any non-2xx answer; when the body is not the envelope (a proxy's HTML page), keep the status and the text.

SMTP is not in the document. Send over SMTP with any client: host smtp.exx.sh, port 465 (TLS) or 587 (STARTTLS), user exx, your API key as the password.

Keep up with a changing document

The document changes when the API does. Most changes add something: an operation, an optional field, an error name. The API is young (0.x) and not yet declared stable, so read the release notes when the document changes. Build your client so that a change is a short, safe chore:

  • Pin a copy. Commit the openapi.json you generated from. Your build uses that copy, never the live URL, so a release of the API never changes your code by itself.

  • Watch for changes. A scheduled job fetches the live document and compares it with your copy; a difference opens a pull request (or fails the job) with the new file:

    curl -sS https://api.exx.sh/openapi.json -o /tmp/live.json
    diff -q <(jq -S . exx-openapi.json) <(jq -S . /tmp/live.json) \
      || echo "the exx.sh API changed: regenerate the client"
  • Regenerate, never edit. Keep generated code apart from your own code (its own directory or module) and regenerate it in one command. Your wrapper holds the retries, defaults and naming.

  • Check coverage of every operation. A test that reads paths.*.*.operationId from your pinned copy and fails when one has no method in your wrapper turns "the API grew" into a failing test instead of a missing feature. The official SDKs run exactly this test.

  • Be lenient when reading. Ignore unknown fields in answers, accept unknown values of enum-like strings (status, last_event, error name), and do not rely on the order of fields or of list items beyond the documented sort.

  • Check your generated code into review. The diff of the generated client shows what changed in the API in terms of your language.

The official SDKs

LanguagePackagePublic source and issuesDocs
TypeScriptnpm install @exx.sh/sdkexx-nodehttps://docs.exx.sh/sdks/typescript
Pythonpip install exx-shexx-pythonhttps://docs.exx.sh/sdks/python
Gogo get github.com/sorvsys/exx-goexx-gohttps://docs.exx.sh/sdks/go
Rustcargo add exx-shexx-rusthttps://docs.exx.sh/sdks/rust

Each is a thin layer over a client generated from this same document, with the behaviours above, plus SMTP sending.

On this page