API reference

Introduction

Base URL, API keys, errors, rate limits, pagination, idempotency and the OpenAPI specification

The Kula API is a REST API that takes and returns JSON.

Base URL

https://api.kulamail.com/v1

HTTPS only. Send JSON bodies with Content-Type: application/json.

For tools that only speak SMTP, use the SMTP relay with the same keys.

Authentication

Pass an API key in the Authorization header:

curl https://api.kulamail.com/v1/me \
  -H "Authorization: Bearer ml_your_api_key"

A key starts with ml_ and is shown once, at creation: store it in a secret manager, never in front-end code. The dashboard then shows only its prefix (ml_a1b2c3d4). Keys of test spaces start with ml_test_.

Space keys and account keys

Space keyAccount key
Created inSettings › API keysAccount › Account API keys
Acts onIts own spaceAny space of the account, chosen with X-Space-Id
Manages spaces (/v1/spaces)NoYes
Manages account webhooks (/v1/account/webhooks)NoYes
Who can create itAdmins and ownersAdmins and owners

Most integrations need a space key. Use an account key when your product creates one space per customer or brand: see Spaces.

With an account key, every route outside /v1/spaces and /v1/account acts on the space named in the X-Space-Id header:

curl https://api.kulamail.com/v1/contacts \
  -H "Authorization: Bearer ml_your_account_key" \
  -H "X-Space-Id: 3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10"

Without the header the API answers 400 space_required. A space key sent with another space's id answers 403 forbidden.

Permissions

Each key has one of two permissions:

  • Full access: every route.
  • Sending access: only the routes below, for servers that just send emails and events.
RouteSending access
POST /v1/emailsYes
POST /v1/emails/batchYes
POST /v1/eventsYes
GET /v1/meYes
Anything elseNo: 403 forbidden

Test your key

GET /v1/me

Returns the key making the request, its account, and the space it acts on.

curl https://api.kulamail.com/v1/me \
  -H "Authorization: Bearer ml_your_api_key"
{
  "key": {
    "name": "Production server",
    "permission": "SENDING_ACCESS",
    "prefix": "ml_a1b2c3d4",
    "test": false
  },
  "account": {
    "id": "b7d2e8f1-4c3a-4e9b-8f60-1a2b3c4d5e6f",
    "name": "Acme"
  },
  "space": {
    "id": "3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10",
    "name": "Acme",
    "test": false
  }
}

test is true for a test key and a test space. space is absent when an account key calls without X-Space-Id.

Errors

Errors use HTTP status codes and always the same body:

{
  "error": "validation_error",
  "message": "email: Email is required",
  "status": 400,
  "fields": {
    "email": "Email is required"
  }
}

error is a stable code to test in your code; message is for humans and may change. fields only appears on validation errors.

StatusCodesWhat happened
400bad_request, validation_error, invalid_body, space_required, invalid_to, invalid_from, domain_not_verified, invalid_url, invalid_blocks, invalid_theme, unsupported_image, image_too_largeThe request is invalid. Read message
401unauthorizedMissing, unknown or revoked API key
402quota_exceededThe monthly sending limit of your plan is reached. See Billing
403forbidden, account_suspendedThe key cannot use this route or this space, or the account is suspended
404not_foundThe resource does not exist in this space
405method_not_allowedWrong HTTP method for this route
409conflict, contact_unreachable, alias_taken, template_not_published, nothing_to_publish, domain_taken, test_space_contact_limit, quota_exceeded (images over 1 GB)The request conflicts with the current state, such as a duplicate alias
413payload_too_largeThe file is over 50 MB
429rate_limitedToo many requests. Wait for Retry-After
500internal_errorSomething broke on our side. Retry later
503unavailableA dependency (DNS, sending provider) is unavailable. Retry later

Rate limits

Each key can make 20 requests per second and 10,000 requests per day (the day resets at midnight UTC).

An account key gets these limits for each space it acts on with X-Space-Id, so its spaces do not share them, within a ceiling of 100 requests per second and 200,000 per day for the key, all spaces together. Its account-level routes (/v1/spaces, /v1/account, /v1/me) count 20 per second and 10,000 per day.

Over a limit, the API answers 429 rate_limited with a Retry-After header in seconds (1 for the per-second limit, the time until midnight UTC for the daily one). The message says which limit was reached.

With POST /v1/emails/batch and POST /v1/contacts/batch, 100 emails or contacts count as one request.

Pagination

List routes that can grow large take a page parameter, starting at 0, and return the totals:

{
  "contacts": [ ... ],
  "page": 0,
  "size": 50,
  "total": 1284,
  "totalPages": 26
}

The page size depends on the resource: contacts take a size parameter (50 by default, 200 at most), suppressions too (50 by default, 100 at most), campaigns come 25 per page.

Idempotency

To retry a send or an event without risking a duplicate, add an Idempotency-Key header. It works on POST /v1/emails and POST /v1/events:

curl https://api.kulamail.com/v1/emails \
  -H "Authorization: Bearer ml_your_api_key" \
  -H "Idempotency-Key: password-reset-7f3a9c" \
  -H "Content-Type: application/json" \
  -d '{ "to": "ada@example.com", "template": "password-reset" }'
  • The key is any string up to 200 characters, unique within the space. Use an id from your own system, such as order-1042-receipt.
  • If an email or an event already exists with that key, the API does nothing and returns the first one with 200 and the header Idempotent-Replayed: true, instead of 201. Emails and events have separate keys.
  • Two concurrent requests with the same key are safe: the second waits for the first and replays it.

Idempotency applies to POST /v1/emails and POST /v1/emails/batch.

Resources

ResourceRoutes
EmailsSend transactional emails, alone or in batches, and read their events
TemplatesReusable emails, with a draft and a published version
ContactsContacts, list subscriptions and bulk imports
EventsRecord what contacts do in your product
Lists and segmentsSubscription lists and saved filters
Campaigns and flowsCreate and schedule campaigns, build and activate flows
Domains and suppressionsSending domains and the suppression list
SpacesSpaces of the account, for account keys
WebhooksEndpoints notified of deliveries, opens, clicks and unsubscribes
Signup formsForms that subscribe readers to lists, with their hosted and embed URLs
Test spacesStaging and integration tests: nothing delivered, simulated outcomes
ChecksPre-send checks of an email
ImagesImages hosted by Kula for your emails
SMTP relaySend transactional emails from any tool that speaks SMTP

OpenAPI specification

The API is described in an OpenAPI 3 file, kept in sync with the routes:

https://api.kulamail.com/openapi.json

Import it in Postman, Insomnia or Bruno, or generate a typed client with OpenAPI Generator:

npx @openapitools/openapi-generator-cli generate   -i https://api.kulamail.com/openapi.json   -g typescript-fetch   -o src/kula

Each route has a stable operation id (sendEmail, upsertContact, createEvent…) that becomes the method name in the generated client.