Skip to main content
Evolution API uses API key authentication via the apikey header. The system supports two levels of authentication: global API keys and per-instance tokens.

Authentication Architecture

Authentication is handled by the auth guard middleware (src/api/guards/auth.guard.ts:10-51) which validates every protected request.

Two-Level Authentication

Evolution API implements a hierarchical authentication model:
  1. Global API Key: Administrative access for creating and managing all instances
  2. Instance Tokens: Scoped access for operations on specific instances
This dual-key system provides security through least-privilege access. Use instance tokens for client applications and reserve the global key for administrative operations.

Global API Key

The global API key provides unrestricted access to all instances and administrative operations.

Configuration

Set the global API key using the AUTHENTICATION_API_KEY environment variable:
.env
Default Value: If not set, the system uses BQYHJGJHJ as the default key. You must change this in production environments.See src/config/env.config.ts:407 for the default configuration.

Using the Global API Key

Include the global API key in the apikey header:

Global Key Permissions

The global API key grants access to:
  • Instance creation: POST /instance/create
  • Fetch all instances: GET /instance/fetchInstances
  • All instance operations: Full CRUD on any instance
  • Administrative endpoints: Metrics, health checks, configuration

Instance Tokens

Each instance has a unique token that provides scoped access to only that instance’s operations.

Token Generation

Instance tokens are set during instance creation:
string
required
A unique identifier for this instance. This becomes the instance’s authentication token.Requirements:
  • Must be unique across all instances
  • Recommended: Use UUID or similar cryptographically random strings
  • Avoid predictable patterns for security

Using Instance Tokens

Once an instance is created, use its token for all instance-specific operations:

Token Scope and Isolation

Instance tokens are validated against the database (src/api/guards/auth.guard.ts:30-35):
Security Boundary: Instance tokens can only access their own instance data. Attempts to access other instances will result in a 401 Unauthorized error, even with a valid token.

Authentication Flow

The authentication guard implements the following flow (src/api/guards/auth.guard.ts:10-51):

Authentication Priority

  1. Global API Key: Checked first, grants immediate access if valid
  2. Instance Token: Checked if global key doesn’t match
  3. Database Validation: Instance tokens are verified against the database

Per-Instance Access Control

Evolution API enforces strict per-instance access control:

Instance Name Validation

All instance-specific endpoints require the instanceName parameter:
The instance name is extracted and validated before processing (src/api/abstract/abstract.router.ts:34).

Database-Level Isolation

All database queries include instance-scoped filters:
This architecture ensures complete data isolation between tenants, even in the event of application-level bugs.

Common Authentication Scenarios

Scenario 1: Administrative Dashboard

Use the global API key for administrative interfaces:

Scenario 2: Client Application

Provide instance tokens to client applications:

Scenario 3: Multi-Instance Management

Use the global key to manage multiple instances:

Authentication Error Responses

Evolution API returns specific error responses for authentication failures:

Missing API Key

Request:
Response (401):
See src/exceptions/401.exception.ts:3-11 for the exception implementation.

Invalid API Key

Request:
Response (401):

Wrong Instance Token

Request:
Response (401):

Missing Global Key for Administrative Operations

Request:
Response (403):
See src/exceptions/403.exception.ts:3-11 for the Forbidden exception.

Verifying Credentials

Test your authentication credentials using the verify endpoint:
Success Response (200):
This endpoint is defined in src/api/routes/index.router.ts:207-216.

Security Best Practices

Follow these security guidelines to protect your Evolution API deployment:

1. Secure API Key Generation

Generate cryptographically secure API keys:

2. Environment Variable Management

Never commit API keys to version control:

3. Key Rotation

Implement regular key rotation:
  • Global keys: Rotate quarterly or after team changes
  • Instance tokens: Rotate when clients request or after security events
  • Process: Create new key → update clients → revoke old key

4. HTTPS Only

Always use HTTPS in production to prevent key interception:

5. IP Allowlisting

Restrict API access to known IP addresses at the infrastructure level (reverse proxy, firewall, or API gateway).

6. Monitor Authentication Failures

Log and alert on repeated authentication failures:

7. Instance Token Management

Control instance token visibility:
When set to false, the /instance/fetchInstances endpoint will not return instance tokens in the response.

Next Steps

Error Handling

Learn about authentication error codes and troubleshooting

Create Instance

Create your first WhatsApp instance

API Overview

Return to API overview

Security

Read the full security documentation