Practical patterns for credentials - environment injection, restricted keys, rotation, and common mistakes.
This guide covers how to wire API credentials into a real application. For the conceptual model see Authentication.
The only thing that should differ between dev, staging, and prod is the key value. Inject it through configuration, never code:
// Works in every environment - the key decides which one it hits.
export const meridian = new Meridian(process.env.MERIDIAN_API_KEY);import os
from meridian import Meridian
meridian = Meridian(os.environ["MERIDIAN_API_KEY"])MERIDIAN_API_KEY=mrnd_test_4f8e2c1a9b7d3e5f6a0cMap each service to the minimum scope set it needs:
| Service | Calls | Scopes |
|---|---|---|
| Read-only dashboard | GET /projects, GET /events | projects:read, events:read |
| Provisioner | POST/PATCH/DELETE /projects | projects:write |
| Webhook manager | endpoint CRUD + replay | webhooks:write |
| Metrics collector | GET /events | events:read |
curl -X POST https://api.meridian.dev/v2/keys \
-H "Authorization: Bearer $MERIDIAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "svc-metrics",
"scopes": ["events:read"],
"expires_in_days": 90
}'The safe rotation order - works for both dashboard and API-driven rotation:
curl -X DELETE https://api.meridian.dev/v2/keys/key_7hF2kLm9xQ \
-H "Authorization: Bearer $MERIDIAN_API_KEY"| Symptom | Likely cause |
|---|---|
401 missing_api_key | Header not sent - check proxy/middleware stripping Authorization |
401 invalid_api_key | Wrong key, revoked, expired, or stray whitespace/newline in env var |
403 insufficient_scope | Restricted key missing resource:action scope |
403 environment_mismatch | Test key pointed at a live-only resource ID |
404 on a resource that exists | You're in the wrong environment - check the key prefix |
Every error response includes request_id - quote it when contacting support; it's the fastest way to trace a call.
For automation, create a dedicated workspace member marked as a service account (Settings → Members → Invite service account):
live environment only).