Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Worker REST API: Versions, Deployments, Static Assets, and Terraform

How Cloudflare's Workers API, SDKs, and Terraform split Worker, Version, and Deployment—and how to upload code and static assets safely.

This page summarizes Cloudflare documentation on programmatic Worker management: the beta resource-oriented REST API, explicit deployments, SDK and Terraform workflows, and static asset uploads. Use it when you automate CI/CD, split platform and app teams, or need predictable version history instead of one-shot script uploads.

Worker, Version, and Deployment: what the new REST API changes

Section titled “Worker, Version, and Deployment: what the new REST API changes”

Cloudflare now lets you manage Worker, Version, and Deployment as separate resources through a beta, resource-oriented API, supported in the Cloudflare Terraform provider and cloudflare-typescript SDK.

You can now manage Workers, Versions, and Deployments as separate resources with a new, resource-oriented API (Beta).

— Cloudflare, A new, simpler REST API for Cloudflare Workers (Beta)

The older upload model was built for a single PUT that sent code and went live immediately. That worked for simple scripts but made team workflows and automation harder.

This API worked for creating a basic Worker, uploading all of its code, and deploying it immediately — but came with challenges:

A Worker couldn’t exist without code: To create a Worker, you had to upload its code in the same API request.

Several endpoints implicitly created deployments: Simple updates like adding a secret or changing a script’s content would implicitly create a new version and immediately deploy it.

Scripts used names as primary identifiers: This meant simple renames could turn into a risky migration… If you were using Terraform, this could inadvertently destroy your Worker altogether.

— Cloudflare, A new, simpler REST API for Cloudflare Workers (Beta)

In plain terms: you could not provision an empty Worker for another team to fill in, small config edits could push production traffic without an explicit release step, and renaming by script name could break IaC state.

What Worker, Version, and Deployment mean now

Section titled “What Worker, Version, and Deployment mean now”

Worker: The parent resource representing your application. It has a stable UUID and holds persistent settings like name, tags, and logpush. You can now create a Worker to establish its identity and settings before any code is uploaded.

Version: An immutable snapshot of your code and its specific configuration, like bindings and compatibility_date. Creating a new version is a safe action that doesn’t affect live traffic.

Deployment: An explicit action that directs traffic to a specific version.

— Cloudflare, A new, simpler REST API for Cloudflare Workers (Beta)

New Worker and Version calls use JSON (modules as base64-encoded strings) instead of mixing responsibilities across many multipart/form-data endpoints.

Resource Typical settings Affects live traffic?
Worker name, tags, logpush, observability No (identity and account-level prefs)
Version bindings, compatibility_date, modules, assets JWT No until deployed
Deployment strategy, version percentages Yes

See Deployment management and Infrastructure as Code (IaC) for end-to-end examples.

Explicit deployments: how to promote a Version without surprise traffic shifts

Section titled “Explicit deployments: how to promote a Version without surprise traffic shifts”

Creating a version and deploying it are now always explicit, separate actions - never implicit side effects. To update version-specific settings (like bindings), you create a new version with those changes. The existing deployed version remains unchanged until you explicitly deploy the new one.

— Cloudflare, A new, simpler REST API for Cloudflare Workers (Beta)

Bind configuration to the right scope: change Worker-level fields with PUT /workers/workers/{id}; change code, bindings, or compatibility_date by creating a new Version; only a Deployment moves customer traffic.

The stable multipart/form-data upload API still exists and implicitly creates a version and deployment. For pipelines that need staging versions, use the beta JSON API or the three-resource Terraform model instead of legacy script PUT when you require an explicit promote step.

Worker UUID vs name: how automation should address a Worker

Section titled “Worker UUID vs name: how automation should address a Worker”

The /workers/workers/ path now supports addressing a Worker by both its immutable UUID and its mutable name.

— Cloudflare, A new, simpler REST API for Cloudflare Workers (Beta)

Use the readable name in dashboards and deployment calls that expect script_name. Use the UUID in automation so renames do not force destroy-and-recreate in Terraform.

Programmatic deploy with SDK: create Worker, Version, then Deployment

Section titled “Programmatic deploy with SDK: create Worker, Version, then Deployment”

Cloudflare API libraries wrap the REST API. The beta flow is: create Worker (no code), create Version, then call client.workers.scripts.deployments.create.

This new API is supported in the Cloudflare Terraform provider ↗︎ and the Cloudflare Typescript SDK ↗︎, allowing platform teams to manage a Worker’s infrastructure in Terraform, while development teams handle code deployments from a separate repository or workflow.

— Cloudflare, A new, simpler REST API for Cloudflare Workers (Beta)

For the legacy one-request style, SDKs accept a structured object and build multipart/form-data for you:

With the new SDK interface, you can now define your entire Worker configuration using a single, structured object… Our SDK takes this logical object and automatically constructs the complex multipart/form-data API request behind the scenes.

— Cloudflare, Automate Worker deployments with a simplified SDK and more reliable Terraform provider

Full script examples live in Infrastructure as Code (IaC) and the cloudflare-typescript script-upload example.

Workers for Platforms: dispatch namespace script upload

Section titled “Workers for Platforms: dispatch namespace script upload”

Platforms that run customer code use the dispatch namespace endpoint described in API examples:

PUT …/accounts/{account_id}/workers/dispatch/namespaces/{namespace}/scripts/{script_name}

Bindings belong in the metadata JSON part of the multipart upload—not in a Wrangler config uploaded as a module (Bindings, Multipart upload metadata).

Terraform: cloudflare_worker, Version, Deployment, and static assets

Section titled “Terraform: cloudflare_worker, Version, Deployment, and static assets”

Infrastructure as Code (IaC) documents two patterns:

  1. Granular (beta): cloudflare_worker → cloudflare_worker_version → cloudflare_workers_deployment
  2. Single resource: cloudflare_workers_script (code, bindings, and optional assets in one apply)

You can declare only cloudflare_worker in Terraform and deploy versions with Wrangler or custom tooling—the resources are intentionally separable.

Worker versions are immutable at the API level, meaning they cannot be updated after creation, only re-created with any desired changes.

— Cloudflare, Infrastructure as Code (IaC)

Each material change to cloudflare_worker_version creates a new API version; old versions remain in history until the parent Worker is deleted. Prefer content_file plus content_sha256 over inline content or large content_base64 in state (Terraform provider improvements).

Full-stack apps: assets directory in Terraform

Section titled “Full-stack apps: assets directory in Terraform”

Now, you simply define the directory where your assets are built, and we handle the rest.

— Cloudflare, You can now deploy full-stack apps on Workers using Terraform

The provider scans the directory, hashes files, uploads missing blobs (same idea as Wrangler), and attaches them to the Worker or Version. Example shapes appear in that changelog and in Infrastructure as Code (IaC).

Static assets API: manifest, upload JWT, and completion token

Section titled “Static assets API: manifest, upload JWT, and completion token”

Direct Uploads and Deploy static assets to User Workers describe the same three phases:

  1. Register manifest — POST …/assets-upload-session with path → { hash, size }
  2. Upload bytes — POST …/workers/assets/upload?base64=true using the session JWT (not the account API token)
  3. Attach to script or version — pass assets.jwt completion token in upload metadata, or use Terraform assets.directory

The asset upload flow can be distilled into three distinct phases: Registration of a manifest, Upload of the assets, Deployment of the Worker

— Cloudflare, Direct Uploads

If all files are already stored, buckets is empty and the session JWT may already be the completion token—skip file upload. Metadata can set keep_assets: true to reuse an existing asset set without re-specifying the JWT (Direct Uploads).

API examples show dispatch-namespace manifests and chunked uploads for platform operators.

Secrets and routes: API fixes and what to use instead of Terraform secrets

Section titled “Secrets and routes: API fixes and what to use instead of Terraform secrets”

The Workers Routes API now returns pattern and script on successful create instead of empty values—important for automation that verifies routing immediately after PUT.

Workers Secrets API is documented in OpenAPI and SDKs. cloudflare_workers_secret and cloudflare_workers_for_platforms_script_secret Terraform resources are not recommended and will be removed; use Secrets Store bindings, secret text on upload, or the Secrets API instead.

Common mistakes when deploying Workers programmatically

Section titled “Common mistakes when deploying Workers programmatically”
  • Treating a Version create as a release — live traffic changes only after an explicit Deployment (changelog).
  • Using account API tokens for asset byte upload — file upload requires the short-lived JWT from assets-upload-session (static assets configuration).
  • Relying on script name as the only ID in Terraform — prefer Worker UUID for stable automation; names remain valid for humans (changelog).
  • Implicit deploy via legacy PUT …/workers/scripts/{name} — fine for quick updates; unsafe when you need unpublished versions (Infrastructure as Code (IaC)).
  • Storing full script bodies in Terraform state — use content_file and content_sha256 on cloudflare_workers_script (provider improvements).
  • Managing secrets only through removed Terraform resources — migrate to supported secret bindings or APIs (API fixes).
  • Skipping bundling and compatibility settings — API uploads expect built modules and correct compatibility_date / flags (Infrastructure as Code (IaC)).
  1. Confirm your account ID and an API token with Workers permissions using Infrastructure as Code (IaC) prerequisites (API token, not Global API Key).
  2. After a beta deploy, GET the Worker by UUID and by name and confirm both resolve to the same resource (changelog).
  3. Create a test Version with a distinct binding, verify production unchanged, then run an explicit Deployment and hit your route or workers.dev URL (Deployment management).
  4. For static assets, re-run assets-upload-session and confirm empty buckets when files are unchanged (Direct Uploads); for Terraform, run terraform plan and expect no diff when code and content_sha256 are unchanged (provider improvements).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.