Per-customer API keys for a WhatsApp platform

Why each customer should get its own scoped key, how to choose scopes and expiry, and how to design issuing, storing and revoking without a leak path.

A platform that exposes WhatsApp sending to its own customers has to decide what credential they hold. Handing every customer the same key is fast and indefensible; handing each one a narrowly scoped key is a small amount of extra work that pays back the first time something leaks. This article covers the design: one key per customer, minimal scopes, expiry, safe issuing and clean revocation.

Why give every customer a separate key?

A separate key limits the blast radius and makes accountability possible. If a key leaks, you revoke one customer's access instead of rotating a credential that every integration depends on, and the audit trail shows which customer did what.

There is a second, quieter benefit: rate limits and quotas become per-customer by construction. CRPRO Hub, for example, applies its request limit per organisation and credential, so separate credentials mean one customer's retry storm does not eat another's budget. The same logic applies to your own platform API: if every call carries a customer-specific key, you can throttle, bill and investigate per customer without extra plumbing.

How should scopes be chosen?

Grant the smallest set of scopes the integration needs and nothing that lets a key manage other keys. A reporting dashboard needs read scopes; a sending service needs send scopes; neither needs the power to create credentials.

Hub keys follow that model. The scopes are channels:read, channels:write, messages:send, templates:read, templates:write, webhooks:read, webhooks:write, billing:read and logs:read. Key management itself is session-only on purpose: a key that authenticates against the key endpoints receives a 403 SESSION_REQUIRED, so a leaked key cannot create replacements for itself or revoke the others. A key also cannot be created with scopes beyond those held by the session creating it.

IntegrationSuggested scopesWhy
Message sendermessages:sendSends only; cannot read history or change webhooks
Reporting joblogs:read, billing:readReads history and usage; cannot send
Template synctemplates:read, templates:writeManages templates only
Provisioning servicechannels:read, channels:write, webhooks:writeCreates lines and registers endpoints; no sending

Notice that creating a channel returns a token that can send messages, so a key that provisions channels also needs messages:send and templates:write on the Hub. Check the authentication page before designing a provisioning role, because that coupling affects which keys count as sensitive.

How should keys be issued and shown?

Show the full secret exactly once, store only a hash or a prefix on your side, and make the customer copy it at creation. Anything that can display the secret again can leak it again.

The Hub does exactly this: the full value of a key (hub_pk_...) appears only in the creation response, listing returns just a prefix, and losing the key means creating another. For your own customer-facing keys, a reasonable pattern is below.

-- your platform's own customer keys CREATE TABLE customer_api_keys ( id uuid PRIMARY KEY, tenant_id uuid NOT NULL, name text NOT NULL, prefix text NOT NULL, -- first characters, safe to display key_hash bytea NOT NULL, -- SHA-256 of the full secret scopes text[] NOT NULL, expires_at timestamptz, revoked_at timestamptz, last_used_at timestamptz ); -- verify: hash the presented key, look it up, check revoked_at and expires_at, -- then check the requested action against scopes.

Use a long random secret and a fast hash such as SHA-256 for lookup; slow password hashes are unnecessary for high-entropy machine secrets. Store last_used_at so customers and your own support team can spot unused keys worth revoking.

When should keys expire and how are they revoked?

Offer an optional expiry on every key, recommend one for automation that is easy to re-issue, and make revocation immediate. A key that stops authenticating at the moment of revocation is the only kind that helps during an incident.

Hub keys accept an optional expires_at in the future; omitted, the key does not expire. Revoking a key keeps it listed with a revoked_at timestamp for audit, while deleting removes it, and a revoked key stops authenticating immediately. Mirror that distinction in your own product: customers want the history, auditors want the history, and nobody wants a deleted row that hides who had access.

  • Rotate by overlap: create the new key, deploy it, confirm traffic on the new key, then revoke the old one.
  • Revoke first, investigate second, when a key appears in a repository or a log.
  • Alert on a revoked key still being presented, since it may indicate a forgotten integration or an attacker.
  • Let customers see key name, prefix, scopes, last use and expiry, but never the secret.

Is a customer key the same as the provider key?

No. There are two separate layers: the key your customer holds against your platform, and the key your platform holds against the WhatsApp provider. Never pass the provider key through to the customer, and never let the customer key authenticate directly against the provider.

Keep the provider credentials server-side, one per tenant when the provider supports it, and map each customer key to the tenant that owns them. That mapping is what lets you swap providers or rotate provider credentials without asking customers to change anything. It also means a customer can never reach another tenant's channels, because the lookup starts from the tenant bound to their key.

If you receive webhooks from the provider on behalf of customers, keep a per-endpoint signing secret as well and verify every delivery; the webhooks reference covers the headers and the signed string.

What should be logged about key use?

Log the key identifier, tenant, action, outcome and time, never the secret or the full Authorization header. With that, an incident review can answer who called what and from where without the logs becoming a second place to steal credentials.

Redact the Authorization header at the proxy layer, scrub request logging libraries that print headers by default, and treat any accidental log of a secret as a leak that requires revocation. The audit log should be append-only for the application role. The Hub exposes an audit log you can page through by cursor and filter by action or by API key, which is the shape worth imitating for your customers.

Frequently asked questions

How many scopes should a single key have?

As few as the integration needs. Separate keys for sending, reporting and provisioning cost nothing and keep a leak from becoming a full compromise.

Should customer keys expire by default?

An expiry is advisable for automation that is easy to re-issue and optional for long-lived integrations. Whatever the default, make revocation immediate and visible in an audit log.

Can a leaked key create more keys?

It should not. Keeping key management behind an interactive session, as the Hub does, means a stolen automation key cannot mint replacements or revoke the legitimate ones.

Fontes

Documentação oficial da Meta, conferida em 31 de outubro de 2026.