Skip to main content
All Ark API requests require authentication using an API key. This guide covers how to create, use, and manage your API keys.

API Key Authentication

Ark uses Bearer token authentication. Include your API key in the Authorization header of every request:
Authorization: Bearer ark_live_xxxxxxxxxxxxxxxxxxxx
Keep your API keys secure. Never expose them in client-side code, public repositories, or logs. Treat API keys like passwords.

Getting Your API Key

API Key Types

TypePrefixUsage
Liveark_live_Production environment
Testark_test_Development and testing
Use test keys during development. They work identically to live keys but won’t send actual emails.

Using the SDKs

The recommended way to authenticate is using an official SDK. All SDKs automatically handle authentication:
from ark import Ark

# Option 1: Pass API key directly
client = Ark(api_key="ark_live_xxxxxxxxxxxxxxxxxxxx")

# Option 2: Use environment variable (recommended)
# Set ARK_API_KEY in your environment, then:
client = Ark()  # Automatically uses ARK_API_KEY

# Send an email
email = client.emails.send(
    from_="[email protected]",
    to=["[email protected]"],
    subject="Hello",
    html="<p>Hello!</p>"
)

Authentication Errors

When authentication fails, the SDK will throw an AuthenticationError:
import ark

try:
    client = Ark(api_key="invalid_key")
    client.emails.send(...)
except ark.AuthenticationError as e:
    print(f"Authentication failed: {e.message}")

Common Causes

ErrorCauseSolution
authentication_requiredMissing Authorization headerAdd Authorization: Bearer <key> header
invalid_api_keyKey format is incorrectEnsure key starts with ark_live_ or ark_test_
expired_api_keyKey has been revokedGenerate a new key from your dashboard

Best Practices

Use Environment Variables

Never hardcode API keys. Use environment variables:
export ARK_API_KEY="ark_live_xxxxxxxxxxxxxxxxxxxx"

Rotate Keys Regularly

  1. Generate a new key in your dashboard
  2. Update your application with the new key
  3. Revoke the old key once the new one is deployed

Use Separate Keys per Environment

Create different keys for:
  • Development (test keys)
  • Staging (test keys)
  • Production (live keys)
This limits blast radius if a key is compromised.

Restrict Key Permissions

When creating keys, grant only the permissions you need:
PermissionDescription
emails:sendSend emails
emails:readRead email status and details
domains:manageCreate and configure domains
webhooks:manageCreate and configure webhooks
suppressions:manageManage suppression list

Rate Limits

API keys are subject to rate limits. See Rate Limits for details.

Next Steps