Skip to main content
Workers for Platforms enables you to deploy Workers on behalf of your customers. This API provides multi-tenant isolation through dispatch namespaces.

Overview

Access the Workers for Platforms API:
import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env.CLOUDFLARE_API_TOKEN,
});

// Access Workers for Platforms
const wfp = client.workersForPlatforms;

Dispatch namespaces

Dispatch namespaces provide isolation between customer Workers in a multi-tenant environment.

Create a dispatch namespace

Create a new namespace for isolating customer Workers.
const namespace = await client.workersForPlatforms.dispatch.namespaces.create({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  name: 'customer-namespace',
});
account_id
string
required
Your Cloudflare account ID
name
string
required
Name for the dispatch namespace
namespace_id
string
The unique identifier for the namespace
name
string
The namespace name
created_on
string
ISO 8601 timestamp when the namespace was created

List dispatch namespaces

Retrieve all dispatch namespaces in your account.
for await (const namespace of client.workersForPlatforms.dispatch.namespaces.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
})) {
  console.log(namespace);
}
account_id
string
required
Your Cloudflare account ID

Get a dispatch namespace

Retrieve details about a specific dispatch namespace.
const namespace = await client.workersForPlatforms.dispatch.namespaces.get(
  'customer-namespace',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);
namespace_name
string
required
The name of the dispatch namespace
account_id
string
required
Your Cloudflare account ID

Delete a dispatch namespace

Delete a dispatch namespace and all Workers within it.
await client.workersForPlatforms.dispatch.namespaces.delete(
  'customer-namespace',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);
namespace_name
string
required
The name of the dispatch namespace to delete
account_id
string
required
Your Cloudflare account ID

Use cases

Multi-tenant SaaS platforms

Use dispatch namespaces to isolate customer code:
// Create a namespace for each customer
const customerNamespace = await client.workersForPlatforms.dispatch.namespaces.create({
  account_id: accountId,
  name: `customer-${customerId}`,
});

// Deploy customer's Worker to their namespace
// This ensures isolation from other customers

Dynamic Worker deployment

Deploy Workers programmatically for your users:
// List all customer namespaces
const namespaces = await client.workersForPlatforms.dispatch.namespaces.list({
  account_id: accountId,
});

// Deploy or update Workers in each namespace as needed
for await (const namespace of namespaces) {
  console.log(`Namespace: ${namespace.name}`);
}

Best practices

  1. Namespace naming: Use a consistent naming convention for customer namespaces (e.g., customer-{id})
  2. Isolation: Each customer should have their own namespace to ensure security and isolation
  3. Cleanup: Delete namespaces when customers churn to free up resources
  4. Monitoring: Track namespace usage and performance per customer

Build docs developers (and LLMs) love