Authentication

SocialRouter uses bearer token authentication. Include your API key in the Authorization header on every request.

Never commit API keys to version control. Use environment variables and rotate keys quarterly.

API key format

All API keys start with sr_ followed by an environment prefix and a unique identifier:

sr_prod_aF93kn28dnQpMzx8kd   # Production key
sr_dev_kJ29djKxnA8aFaj3mf    # Development key
sr_test_oP38aFbXcVnMq9wn     # Testing key

Authenticating requests

import socialrouter

# Option 1: Pass directly
client = socialrouter.Client("sr_prod_your_key")

# Option 2: Environment variable (recommended)
import os
client = socialrouter.Client(os.environ["SOCIALROUTER_API_KEY"])

Errors

CodeErrorMeaning
401missing_credentialsNo Authorization header sent.
401invalid_credentialsKey is malformed, expired, or doesn't exist.
403key_revokedKey was manually revoked. Create a new key.
429rate_limitedToo many requests. See Retry-After header.
402insufficient_creditsAccount balance is zero. Top up to continue.

Rotating keys

Best practice: rotate keys quarterly or whenever team membership changes. To rotate:

  1. Create a new key in the dashboard
  2. Deploy your application with the new key
  3. Verify the new key is working (check recent calls)
  4. Revoke the old key

Old keys continue working until you explicitly revoke them — no surprise outages.