Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

Secure authentication


Secure authentication provides the foundation of API security. To verify that you granted the requester permission to your account resources, Twilio requires authentication on every API request.

When you create a Twilio account, Twilio generates an Account SID and an Auth Token. The Auth Token provides broad account access and should be protected like a high-privilege password.


Supported authentication methods

supported-authentication-methods page anchor

Twilio supports three authentication methods. Choose based on your security requirements and integration needs:

  1. OAuth 2.0 — Recommended for new integrations
    • Short-lived access tokens, as brief as one minute
    • Scoped to specific permissions
    • Best for third-party apps and delegated access
    • Requires token refresh mechanism
  2. API Keys — Recommended for server-side apps
    • Main API Key: Provides broad account access (avoid for new integrations)
    • Standard API Key: Full account access with SID isolation
    • Restricted API Key: Scoped to specific capabilities (recommended for new integrations)
  3. Auth Token authentication — Legacy option
    • Provides broad account access
    • Should only be used when OAuth 2.0 or API keys are not supported
    • Treat as last-resort option

Choosing the right authentication method

choosing-the-right-authentication-method page anchor

Whenever the integration supports OAuth 2.0 or a Restricted API Key, use it. These options allow you to scope access to the capabilities your integration needs. This limits the potential impact of a leaked credential.

Auth Tokens and Main API Keys provide broad account access. Although they remain supported, treat them as legacy or last-resort options rather than the default for new integrations.

The following table compares key attributes of each authentication method:

MethodScope controlToken lifetimeRecommended useSecurity level
OAuth 2.0Highly scopedShort-lived (configurable)Third-party apps, delegated accessHighest
Restricted API KeyScoped to capabilitiesLong-lived (until revoked)Server-side appsHigh
Standard API KeyAccount-level accessLong-lived (until revoked)Admin access, account managementMedium
Auth TokenBroad account accessLong-lived (until rotated)Legacy integrations onlyLow

OAuth 2.0 and SDK support

oauth-20-and-sdk-support page anchor

OAuth 2.0 provides the strongest security posture for API authentication. To simplify implementation, Twilio provides SDK support for OAuth. These SDKs refresh tokens and reduce the amount of code that you must implement for authentication. This reduces the risk of expired token errors.


Best practices for all authentication methods

best-practices-for-all-authentication-methods page anchor

Implement the following practices regardless of which authentication method you choose:

  • Prefer short-lived OAuth 2.0 access tokens where appropriate.
  • Rotate client credentials and signing keys according to organizational policy.
  • Revoke credentials immediately when you suspect compromise.
  • Grant each integration only the permissions it needs.
  • Keep authentication logic on the server side and out of browser-delivered code.
  • Never hardcode credentials in source code or client-side apps.
  • Store all credentials in a secrets manager.

Learn more about securing your Twilio integration: