Skip to main content

Cloudflare Workers

Authenticate API keys in Cloudflare Workers with Unkey. A copy-paste recipe for low-latency, edge-based key verification using @unkey/api.
1 min read

Protect your Cloudflare Workers with Unkey's globally distributed verification.

Install#

Basic Worker#

src/index.ts

Configure Secrets#


With Hono#

For a cleaner routing experience, use Hono:

src/index.ts

Reusable Auth Middleware#

Create a clean middleware pattern:

src/middleware/auth.ts

Use it:

src/index.ts

Rate Limit Headers#

Add standard rate limit headers:

src/middleware/auth.ts

With Durable Objects#

For stateful applications with Durable Objects:

src/index.ts

wrangler.toml#

wrangler.toml

Deploy#

Your API is now protected globally with Unkey! 🌍