Skip to main content
The Cloudflare provider enables you to deploy and manage Cloudflare Workers, Durable Objects, databases, storage, and other edge infrastructure using TypeScript.

Installation

The Cloudflare provider is included in the main alchemy package:
npm install alchemy

Credentials

Set up your Cloudflare credentials as environment variables:
export CLOUDFLARE_API_TOKEN="your-api-token"
export CLOUDFLARE_ACCOUNT_ID="your-account-id"
Create an API token at dash.cloudflare.com/profile/api-tokens with the Edit Cloudflare Workers template.

Available resources

Compute

Storage

Messaging & Queues

  • Queue - Message queues for async processing
  • DispatchNamespace - RPC between Workers

AI & ML

  • AiSearch - RAG and semantic search
  • Ai - Access Cloudflare AI models

Networking

  • CustomDomain - Custom domains for Workers
  • Hyperdrive - Database connection pooling
  • Tunnel - Secure tunnels to your origin
  • Route - HTTP routing rules

Security

  • ApiShield - API security and validation
  • RateLimit - Rate limiting rules

Example usage

Here’s a complete example deploying a Worker with Durable Objects, R2 storage, and a Queue:
import alchemy from "alchemy";
import {
  Worker,
  DurableObjectNamespace,
  R2Bucket,
  Queue,
  D1Database,
} from "alchemy/cloudflare";

const app = await alchemy("cloudflare-app");

// Storage
const bucket = await R2Bucket("storage", {
  name: `${app.name}-${app.stage}-storage`,
});

const db = await D1Database("db", {
  name: `${app.name}-${app.stage}-db`,
});

// Queue for async processing
const queue = await Queue<{ userId: string; action: string }>("tasks", {
  name: `${app.name}-${app.stage}-tasks`,
});

// Durable Object for stateful compute
const sessions = await DurableObjectNamespace("sessions", {
  className: "SessionManager",
  script: "./src/durable-objects.ts",
});

// Worker
const worker = await Worker("api", {
  name: `${app.name}-${app.stage}-api`,
  entrypoint: "./src/worker.ts",
  bindings: {
    BUCKET: bucket,
    DB: db,
    QUEUE: queue,
    SESSIONS: sessions,
  },
  url: true, // Enable workers.dev subdomain
  eventSources: [
    {
      queue,
      settings: {
        batchSize: 10,
        maxWaitTimeMs: 5000,
      },
    },
  ],
});

console.log(`Worker URL: ${worker.url}`);

await app.finalize();

Local development

Cloudflare resources support local development mode using Miniflare:
const app = await alchemy("my-app", {
  local: true, // Enable local mode
});

// Resources run locally with Miniflare
const worker = await Worker("worker", {
  entrypoint: "./src/index.ts",
  bindings: {
    // Local bindings work the same way
  },
});

// Access via localhost
console.log(`Local URL: http://localhost:${worker.port}`);
See the Local Development guide for more details.

Framework integrations

Alchemy provides plugins for popular web frameworks:

Next steps

Worker API

Deploy Cloudflare Workers

Durable Objects

Stateful serverless compute

Examples

Browse Cloudflare examples

Framework integrations

Deploy web frameworks

Build docs developers (and LLMs) love