API keys

Reference API key formats, the X-API-Key header, rate limits, and authentication errors for Samva's email API.

Samva authenticates email API requests with an API key sent in the X-API-Key header. This page documents key format, request authentication, rate limiting, and authentication errors. For the model behind keys, how one binds to an organization and scopes every request, see Organizations and tenancy.

API key format

Production keys start with samva_sk_live_; keys minted outside production start with samva_sk_test_. Each key authenticates requests for the organization it belongs to.

Using API keys

Include the key in the X-API-Key header on every request.

The SDK reads the key from the apiKey option and sets the header for you.

import { createClient } from "samva";

const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });

Store keys in environment variables, never in source. The full key value is shown only once at creation time.

Key handling

PracticeDetail
Use environment variablesRead the key from the environment; never hardcode it in source.
Scope permissionsSet the minimum permissions required when creating a key.
Rotate keysReplace keys periodically and after any suspected exposure.
Monitor usageTrack per-key usage in the Samva Dashboard.

Key lifecycle

Keys are created and managed under Developers → API Keys in the Samva Dashboard. Each key carries a set of permissions and an optional expiry, both set at creation. The full key value is returned only at creation time and is not retrievable afterward; a lost key must be replaced. Keys can be revoked at any time, and a revoked key stops authenticating immediately.

Rate limiting

Send throughput is rate limited per organization. When a limit is exceeded, the request returns 429 Too Many Requests with a RateLimitedError body. The retryAfterSeconds field tells you how long to wait before retrying.

{
  "_tag": "RateLimitedError",
  "retryAfterSeconds": 30
}

Back off for at least retryAfterSeconds seconds before sending the request again.

Authentication errors

Errors are returned as tagged JSON bodies. Each body carries a _tag identifying the error and a message describing it.

Status_tagDescriptionResolution
401UnauthorizedErrorInvalid or missing API keyCheck the X-API-Key header value
403ForbiddenErrorInsufficient permissionsUse a key with the required scope

Invalid or missing API key

Returned when the API key cannot be validated.

{
  "_tag": "UnauthorizedError",
  "message": "Invalid API key"
}

Insufficient permissions

Returned when the key is valid but not authorized for the request, for example a key without the scope the endpoint requires.

{
  "_tag": "ForbiddenError",
  "message": "API key lacks the required permission"
}

These are the authentication-specific errors. For the full list the API can return, with each error's fields and how to resolve it, see the Error reference.

On this page