Skip to main content

Authentication

How to authenticate channel-sending requests and AI Gateway requests.

3 min read

Mersal's API uses two separate authentication mechanisms, depending on which endpoint family you're calling. They use different key types generated in different places in the dashboard, and are not interchangeable.

Channel-sending endpoints (Api-key)

POST /api/sms/send, POST /api/whatsapp/send, POST /api/email/send, and their corresponding GET /api/get/{channel}/{id?} lookup endpoints authenticate with your personal API key. Mersal checks for the key in this order:

  1. Header Api-key: <your-api-key> (recommended)
  2. Query parameter ?api_key=<your-api-key>
  3. POST body field api_key

Not a Bearer token

The header name is genuinely Api-key, not Authorization: Bearer. Don't use Bearer-token style for the channel-sending endpoints — that style is reserved for the AI Gateway only.

Finding your API key

Open your account settings

Sign in to the Mersal dashboard and open your account settings.

Open the API key page

Your personal API key is displayed there, and can be regenerated at any time.

Store it securely

Treat it like a password — anyone with this key can send messages and spend your account's sending credits. Keep it in an environment variable, never in your code. See API Key Management.

Example in every language

curl -X POST https://mersal.it/api/sms/send \
  -H "Api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contact":[{"number":"+201234567890","message":"Hello from Mersal"}]}'

Subscription requirement

Channel-sending endpoints require an active subscription/plan on your account. If your plan has expired, every request returns 403 regardless of whether the API key itself is valid:

{
  "status": "error",
  "error": "Your Subscription Is Expired! Buy A New Plan"
}

AI Gateway (Bearer token)

POST /api/ai/v1/chat/completions and GET /api/ai/v1/models use a different key type: an AI Pool key, created specifically for AI Gateway access, sent as a standard Bearer token:

Authorization: Bearer <ai-pool-key>
curl https://mersal.it/api/ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_AI_POOL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"Hello"}]}'

AI Pool keys are generated separately from your channel API key — look for the AI Pool / AI Gateway section of the dashboard. See AI Gateway: Chat Completions for the full request/response contract.

Error responses

ScenarioStatusBody
API key missing (channel endpoints)403{"status":"error","message":"API key is required. Provide via header (Api-key) or URL parameter (api_key)","error":"Invalid Api Key"}
API key invalid (channel endpoints)403{"status":"error","error":"Invalid Api Key"}
Subscription expired403{"status":"error","error":"Your Subscription Is Expired! Buy A New Plan"}

For the full list of error conventions, see Errors and Status Codes.

Was this page helpful?
Authentication · Mersal Docs