Skip to content
Start here

Upload Worker Module

client.workers.scripts.update(stringscriptName, ScriptUpdateParams { account_id, metadata, bindings_inherit, files } params, RequestOptionsoptions?): ScriptUpdateResponse { startup_time_ms, id, compatibility_date, 20 more }
PUT/accounts/{account_id}/workers/scripts/{script_name}

Upload a worker module. You can find more about the multipart metadata on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Workers Scripts Write
ParametersExpand Collapse
scriptName: string

Name of the script, used in URLs and route configuration.

params: ScriptUpdateParams { account_id, metadata, bindings_inherit, files }
account_id: string

Path param: Identifier.

maxLength32
metadata: Metadata

Body param: JSON-encoded metadata about the uploaded parts and Worker configuration.

annotations?: Annotations { workers/message, workers/tag }

Annotations for the version created by this upload.

"workers/message"?: string

Human-readable message about the version.

maxLength100
"workers/tag"?: string

User-provided identifier for the version.

maxLength25
assets?: Assets { config, jwt }

Configuration for assets within a Worker.

config?: Config { _headers, _redirects, html_handling, 3 more }

Configuration for assets within a Worker.

_headers?: string

The contents of a _headers file (used to attach custom headers on asset responses).

_redirects?: string

The contents of a _redirects file (used to apply redirects or proxy paths ahead of asset serving).

html_handling?: "auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash" | "none"

Determines the redirects and rewrites of requests for HTML content.

One of the following:
"auto-trailing-slash"
"force-trailing-slash"
"drop-trailing-slash"
"none"
not_found_handling?: "none" | "404-page" | "single-page-application"

Determines the response when a request does not match a static asset, and there is no Worker script.

One of the following:
"none"
"404-page"
"single-page-application"
run_worker_first?: Array<string> | boolean

Contains a list path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.

One of the following:
Array<string>
boolean
Deprecatedserve_directly?: boolean

When true and the incoming request matches an asset, that will be served instead of invoking the Worker script. When false, requests will always invoke the Worker script.

jwt?: string

Token provided upon successful upload of all files from a registered manifest.

bindings?: Array<WorkersBindingKindAI { name, type } | WorkersBindingKindAISearch { instance_name, name, type, namespace } | WorkersBindingKindAISearchNamespace { name, namespace, type } | 31 more>

List of bindings attached to a Worker. You can find more about bindings on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.

One of the following:
WorkersBindingKindAI { name, type }
name: string

A JavaScript variable name for the binding.

type: "ai"

The kind of resource that the binding provides.

WorkersBindingKindAISearch { instance_name, name, type, namespace }
instance_name: string

The user-chosen instance name. Must exist at deploy time. The worker can search, chat, update, and manage items/jobs on this instance.

name: string

A JavaScript variable name for the binding.

type: "ai_search"

The kind of resource that the binding provides.

namespace?: string

The namespace the instance belongs to. Defaults to "default" if omitted. Customers who don't use namespaces can simply omit this field.

WorkersBindingKindAISearchNamespace { name, namespace, type }
name: string

A JavaScript variable name for the binding.

namespace: string

The user-chosen namespace name. Must exist before deploy -- Wrangler handles auto-creation on deploy failure (R2 bucket pattern). The "default" namespace is auto-created by config-api for new accounts. Grants full access (CRUD + search + chat) to all instances within the namespace.

type: "ai_search_namespace"

The kind of resource that the binding provides.

WorkersBindingKindAnalyticsEngine { dataset, name, type }
dataset: string

The name of the dataset to bind to.

name: string

A JavaScript variable name for the binding.

type: "analytics_engine"

The kind of resource that the binding provides.

WorkersBindingKindAssets { name, type }
name: string

A JavaScript variable name for the binding.

type: "assets"

The kind of resource that the binding provides.

WorkersBindingKindBrowser { name, type }
name: string

A JavaScript variable name for the binding.

type: "browser"

The kind of resource that the binding provides.

WorkersBindingKindD1 { id, name, type }
id: string

Identifier of the D1 database to bind to.

name: string

A JavaScript variable name for the binding.

type: "d1"

The kind of resource that the binding provides.

WorkersBindingKindDataBlob { name, part, type }
name: string

A JavaScript variable name for the binding.

part: string

The name of the file containing the data content. Only accepted for service worker syntax Workers.

Deprecatedtype: "data_blob"

The kind of resource that the binding provides.

WorkersBindingKindDispatchNamespace { name, namespace, type, outbound }
name: string

A JavaScript variable name for the binding.

namespace: string

The name of the dispatch namespace.

type: "dispatch_namespace"

The kind of resource that the binding provides.

outbound?: Outbound { params, worker }

Outbound worker.

params?: Array<Param>

Pass information from the Dispatch Worker to the Outbound Worker through the parameters.

name: string

Name of the parameter.

worker?: Worker { entrypoint, environment, service }

Outbound worker.

entrypoint?: string

Entrypoint to invoke on the outbound worker.

environment?: string

Environment of the outbound worker.

service?: string

Name of the outbound worker.

WorkersBindingKindDurableObjectNamespace { name, type, class_name, 4 more }
name: string

A JavaScript variable name for the binding.

type: "durable_object_namespace"

The kind of resource that the binding provides.

class_name?: string

The exported class name of the Durable Object.

dispatch_namespace?: string

The dispatch namespace the Durable Object script belongs to.

environment?: string

The environment of the script_name to bind to.

namespace_id?: string

Namespace identifier tag.

maxLength32
script_name?: string

The script where the Durable Object is defined, if it is external to this Worker.

WorkersBindingKindHyperdrive { id, name, type }
id: string

Identifier of the Hyperdrive connection to bind to.

name: string

A JavaScript variable name for the binding.

type: "hyperdrive"

The kind of resource that the binding provides.

WorkersBindingKindInherit { name, type, old_name, version_id }
name: string

The name of the inherited binding.

type: "inherit"

The kind of resource that the binding provides.

old_name?: string

The old name of the inherited binding. If set, the binding will be renamed from old_name to name in the new version. If not set, the binding will keep the same name between versions.

version_id?: string

Identifier for the version to inherit the binding from, which can be the version ID or the literal "latest" to inherit from the latest version. Defaults to inheriting the binding from the latest version.

WorkersBindingKindImages { name, type }
name: string

A JavaScript variable name for the binding.

type: "images"

The kind of resource that the binding provides.

WorkersBindingKindJson { json, name, type }
json: unknown

JSON data to use.

name: string

A JavaScript variable name for the binding.

type: "json"

The kind of resource that the binding provides.

WorkersBindingKindKVNamespace { name, namespace_id, type }
name: string

A JavaScript variable name for the binding.

namespace_id: string

Namespace identifier tag.

maxLength32
type: "kv_namespace"

The kind of resource that the binding provides.

WorkersBindingKindMedia { name, type }
name: string

A JavaScript variable name for the binding.

type: "media"

The kind of resource that the binding provides.

WorkersBindingKindMTLSCertificate { certificate_id, name, type }
certificate_id: string

Identifier of the certificate to bind to.

name: string

A JavaScript variable name for the binding.

type: "mtls_certificate"

The kind of resource that the binding provides.

WorkersBindingKindPlainText { name, text, type }
name: string

A JavaScript variable name for the binding.

text: string

The text value to use.

type: "plain_text"

The kind of resource that the binding provides.

WorkersBindingKindPipelines { name, pipeline, type }
name: string

A JavaScript variable name for the binding.

pipeline: string

Name of the Pipeline to bind to.

type: "pipelines"

The kind of resource that the binding provides.

WorkersBindingKindQueue { name, queue_name, type }
name: string

A JavaScript variable name for the binding.

queue_name: string

Name of the Queue to bind to.

type: "queue"

The kind of resource that the binding provides.

WorkersBindingKindRatelimit { name, namespace_id, simple, type }
name: string

A JavaScript variable name for the binding.

namespace_id: string

Identifier of the rate limit namespace to bind to.

simple: Simple { limit, period }

The rate limit configuration.

limit: number

The limit (requests per period).

period: number

The period in seconds.

type: "ratelimit"

The kind of resource that the binding provides.

WorkersBindingKindR2Bucket { bucket_name, name, type, jurisdiction }
bucket_name: string

R2 bucket to bind to.

name: string

A JavaScript variable name for the binding.

type: "r2_bucket"

The kind of resource that the binding provides.

jurisdiction?: "eu" | "fedramp" | "fedramp-high"

The jurisdiction of the R2 bucket.

One of the following:
"eu"
"fedramp"
"fedramp-high"
WorkersBindingKindSecretText { name, text, type }
name: string

A JavaScript variable name for the binding.

text: string

The secret value to use.

type: "secret_text"

The kind of resource that the binding provides.

WorkersBindingKindSendEmail { name, type, allowed_destination_addresses, 2 more }
name: string

A JavaScript variable name for the binding.

type: "send_email"

The kind of resource that the binding provides.

allowed_destination_addresses?: Array<string>

List of allowed destination addresses.

allowed_sender_addresses?: Array<string>

List of allowed sender addresses.

destination_address?: string

Destination address for the email.

formatemail
WorkersBindingKindService { name, service, type, 2 more }
name: string

A JavaScript variable name for the binding.

service: string

Name of Worker to bind to.

type: "service"

The kind of resource that the binding provides.

entrypoint?: string

Entrypoint to invoke on the target Worker.

environment?: string

Optional environment if the Worker utilizes one.

WorkersBindingKindTextBlob { name, part, type }
name: string

A JavaScript variable name for the binding.

part: string

The name of the file containing the text content. Only accepted for service worker syntax Workers.

Deprecatedtype: "text_blob"

The kind of resource that the binding provides.

WorkersBindingKindVectorize { index_name, name, type }
index_name: string

Name of the Vectorize index to bind to.

name: string

A JavaScript variable name for the binding.

type: "vectorize"

The kind of resource that the binding provides.

WorkersBindingKindVersionMetadata { name, type }
name: string

A JavaScript variable name for the binding.

type: "version_metadata"

The kind of resource that the binding provides.

WorkersBindingKindSecretsStoreSecret { name, secret_name, store_id, type }
name: string

A JavaScript variable name for the binding.

secret_name: string

Name of the secret in the store.

store_id: string

ID of the store containing the secret.

type: "secrets_store_secret"

The kind of resource that the binding provides.

WorkersBindingKindSecretKey { algorithm, format, name, 4 more }
algorithm: unknown

Algorithm-specific key parameters. Learn more.

format: "raw" | "pkcs8" | "spki" | "jwk"

Data format of the key. Learn more.

One of the following:
"raw"
"pkcs8"
"spki"
"jwk"
name: string

A JavaScript variable name for the binding.

type: "secret_key"

The kind of resource that the binding provides.

usages: Array<"encrypt" | "decrypt" | "sign" | 5 more>

Allowed operations with the key. Learn more.

One of the following:
"encrypt"
"decrypt"
"sign"
"verify"
"deriveKey"
"deriveBits"
"wrapKey"
"unwrapKey"
key_base64?: string

Base64-encoded key data. Required if format is "raw", "pkcs8", or "spki".

key_jwk?: unknown

Key data in JSON Web Key format. Required if format is "jwk".

WorkersBindingKindWorkflow { name, type, workflow_name, 2 more }
name: string

A JavaScript variable name for the binding.

type: "workflow"

The kind of resource that the binding provides.

workflow_name: string

Name of the Workflow to bind to.

class_name?: string

Class name of the Workflow. Should only be provided if the Workflow belongs to this script.

script_name?: string

Script name that contains the Workflow. If not provided, defaults to this script name.

WorkersBindingKindWasmModule { name, part, type }
name: string

A JavaScript variable name for the binding.

part: string

The name of the file containing the WebAssembly module content. Only accepted for service worker syntax Workers.

Deprecatedtype: "wasm_module"

The kind of resource that the binding provides.

WorkersBindingKindVPCService { name, service_id, type }
name: string

A JavaScript variable name for the binding.

service_id: string

Identifier of the VPC service to bind to.

type: "vpc_service"

The kind of resource that the binding provides.

WorkersBindingKindVPCNetwork { name, type, network_id, tunnel_id }
name: string

A JavaScript variable name for the binding.

type: "vpc_network"

The kind of resource that the binding provides.

network_id?: string

Identifier of the network to bind to. Only "cf1:network" is currently supported. Mutually exclusive with tunnel_id.

tunnel_id?: string

UUID of the Cloudflare Tunnel to bind to. Mutually exclusive with network_id.

body_part?: string

Name of the uploaded file that contains the script (e.g. the file adding a listener to the fetch event). Indicates a service worker syntax Worker.

compatibility_date?: string

Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.

compatibility_flags?: Array<string>

Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.

keep_assets?: boolean

Retain assets which exist for a previously uploaded Worker version; used in lieu of providing a completion token.

keep_bindings?: Array<string>

List of binding types to keep from previous_upload.

limits?: Limits { cpu_ms }

Limits to apply for this Worker.

cpu_ms?: number

The amount of CPU time this Worker can use in milliseconds.

logpush?: boolean

Whether Logpush is turned on for the Worker.

main_module?: string

Name of the uploaded file that contains the main module (e.g. the file exporting a fetch handler). Indicates a module syntax Worker.

migrations?: SingleStepMigration { deleted_classes, new_classes, new_sqlite_classes, 4 more } | WorkersMultipleStepMigrations { new_tag, old_tag, steps }

Migrations to apply for Durable Objects associated with this Worker.

One of the following:
SingleStepMigration { deleted_classes, new_classes, new_sqlite_classes, 4 more }

A single set of migrations to apply.

deleted_classes?: Array<string>

A list of classes to delete Durable Object namespaces from.

new_classes?: Array<string>

A list of classes to create Durable Object namespaces from.

new_sqlite_classes?: Array<string>

A list of classes to create Durable Object namespaces with SQLite from.

new_tag?: string

Tag to set as the latest migration tag.

old_tag?: string

Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.

renamed_classes?: Array<RenamedClass>

A list of classes with Durable Object namespaces that were renamed.

from?: string
to?: string
transferred_classes?: Array<TransferredClass>

A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.

from?: string
from_script?: string
to?: string
WorkersMultipleStepMigrations { new_tag, old_tag, steps }
new_tag?: string

Tag to set as the latest migration tag.

old_tag?: string

Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.

steps?: Array<MigrationStep { deleted_classes, new_classes, new_sqlite_classes, 2 more } >

Migrations to apply in order.

deleted_classes?: Array<string>

A list of classes to delete Durable Object namespaces from.

new_classes?: Array<string>

A list of classes to create Durable Object namespaces from.

new_sqlite_classes?: Array<string>

A list of classes to create Durable Object namespaces with SQLite from.

renamed_classes?: Array<RenamedClass>

A list of classes with Durable Object namespaces that were renamed.

from?: string
to?: string
transferred_classes?: Array<TransferredClass>

A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.

from?: string
from_script?: string
to?: string
observability?: Observability { enabled, head_sampling_rate, logs, traces }

Observability settings for the Worker.

enabled: boolean

Whether observability is enabled for the Worker.

head_sampling_rate?: number | null

The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

logs?: Logs | null

Log settings for the Worker.

enabled: boolean

Whether logs are enabled for the Worker.

invocation_logs: boolean

Whether invocation logs are enabled for the Worker.

destinations?: Array<string>

A list of destinations where logs will be exported to.

head_sampling_rate?: number | null

The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist?: boolean

Whether log persistence is enabled for the Worker.

traces?: Traces | null

Trace settings for the Worker.

destinations?: Array<string>

A list of destinations where traces will be exported to.

enabled?: boolean

Whether traces are enabled for the Worker.

head_sampling_rate?: number | null

The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist?: boolean

Whether trace persistence is enabled for the Worker.

placement?: UnionMember0 { mode, last_analyzed_at, status } | UnionMember1 { region, last_analyzed_at, status } | UnionMember2 { hostname, last_analyzed_at, status } | 5 more

Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.

One of the following:
UnionMember0 { mode, last_analyzed_at, status }
mode: "smart"

Enables Smart Placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember1 { region, last_analyzed_at, status }
region: string

Cloud region for targeted placement in format 'provider:region'.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember2 { hostname, last_analyzed_at, status }
hostname: string

HTTP hostname for targeted placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember3 { host, last_analyzed_at, status }
host: string

TCP host and port for targeted placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember4 { mode, region, last_analyzed_at, status }
mode: "targeted"

Targeted placement mode.

region: string

Cloud region for targeted placement in format 'provider:region'.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember5 { hostname, mode, last_analyzed_at, status }
hostname: string

HTTP hostname for targeted placement.

mode: "targeted"

Targeted placement mode.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember6 { host, mode, last_analyzed_at, status }
host: string

TCP host and port for targeted placement.

mode: "targeted"

Targeted placement mode.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember7 { mode, target, last_analyzed_at, status }
mode: "targeted"

Targeted placement mode.

target: Array<Region { region } | Hostname { hostname } | Host { host } >

Array of placement targets (currently limited to single target).

One of the following:
Region { region }
region: string

Cloud region in format 'provider:region'.

Hostname { hostname }
hostname: string

HTTP hostname for targeted placement.

Host { host }
host: string

TCP host:port for targeted placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
tags?: Array<string>

List of strings to use as tags for this Worker.

tail_consumers?: Array<ConsumerScript { service, environment, namespace } > | null

List of Workers that will consume logs from the attached Worker.

service: string

Name of Worker that is to be the consumer.

environment?: string

Optional environment if the Worker utilizes one.

namespace?: string

Optional dispatch namespace the script belongs to.

usage_model?: "standard" | "bundled" | "unbound"

Usage model for the Worker invocations.

One of the following:
"standard"
"bundled"
"unbound"
bindings_inherit?: "strict"

Query param: When set to "strict", the upload will fail if any inherit type bindings cannot be resolved against the previous version of the Worker. Without this, unresolvable inherit bindings are silently dropped.

files?: Array<Uploadable>

Body param: An array of modules (often JavaScript files) comprising a Worker script. At least one module must be present and referenced in the metadata as main_module or body_part by filename.
Possible Content-Type(s) are: application/javascript+module, text/javascript+module, application/javascript, text/javascript, text/x-python, text/x-python-requirement, application/wasm, text/plain, application/octet-stream, application/source-map.

ReturnsExpand Collapse
ScriptUpdateResponse { startup_time_ms, id, compatibility_date, 20 more }
startup_time_ms: number
id?: string

The name used to identify the script.

compatibility_date?: string

Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.

compatibility_flags?: Array<string>

Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.

created_on?: string

When the script was created.

formatdate-time
entry_point?: string

The entry point for the script.

etag?: string

Hashed script content, can be used in a If-None-Match header when updating.

handlers?: Array<string>

The names of handlers exported as part of the default export.

has_assets?: boolean

Whether a Worker contains assets.

has_modules?: boolean

Whether a Worker contains modules.

last_deployed_from?: string

The client most recently used to deploy this Worker.

logpush?: boolean

Whether Logpush is turned on for the Worker.

migration_tag?: string

The tag of the Durable Object migration that was most recently applied for this Worker.

modified_on?: string

When the script was last modified.

formatdate-time
named_handlers?: Array<NamedHandler>

Named exports, such as Durable Object class implementations and named entrypoints.

handlers?: Array<string>

The names of handlers exported as part of the named export.

name?: string

The name of the export.

observability?: Observability { enabled, head_sampling_rate, logs, traces }

Observability settings for the Worker.

enabled: boolean

Whether observability is enabled for the Worker.

head_sampling_rate?: number | null

The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

logs?: Logs | null

Log settings for the Worker.

enabled: boolean

Whether logs are enabled for the Worker.

invocation_logs: boolean

Whether invocation logs are enabled for the Worker.

destinations?: Array<string>

A list of destinations where logs will be exported to.

head_sampling_rate?: number | null

The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist?: boolean

Whether log persistence is enabled for the Worker.

traces?: Traces | null

Trace settings for the Worker.

destinations?: Array<string>

A list of destinations where traces will be exported to.

enabled?: boolean

Whether traces are enabled for the Worker.

head_sampling_rate?: number | null

The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist?: boolean

Whether trace persistence is enabled for the Worker.

placement?: UnionMember0 { mode, last_analyzed_at, status } | UnionMember1 { region, last_analyzed_at, status } | UnionMember2 { hostname, last_analyzed_at, status } | 5 more

Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.

One of the following:
UnionMember0 { mode, last_analyzed_at, status }
mode: "smart"

Enables Smart Placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember1 { region, last_analyzed_at, status }
region: string

Cloud region for targeted placement in format 'provider:region'.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember2 { hostname, last_analyzed_at, status }
hostname: string

HTTP hostname for targeted placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember3 { host, last_analyzed_at, status }
host: string

TCP host and port for targeted placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember4 { mode, region, last_analyzed_at, status }
mode: "targeted"

Targeted placement mode.

region: string

Cloud region for targeted placement in format 'provider:region'.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember5 { hostname, mode, last_analyzed_at, status }
hostname: string

HTTP hostname for targeted placement.

mode: "targeted"

Targeted placement mode.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember6 { host, mode, last_analyzed_at, status }
host: string

TCP host and port for targeted placement.

mode: "targeted"

Targeted placement mode.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
UnionMember7 { mode, target, last_analyzed_at, status }
mode: "targeted"

Targeted placement mode.

target: Array<Region { region } | Hostname { hostname } | Host { host } >

Array of placement targets (currently limited to single target).

One of the following:
Region { region }
region: string

Cloud region in format 'provider:region'.

Hostname { hostname }
hostname: string

HTTP hostname for targeted placement.

Host { host }
host: string

TCP host:port for targeted placement.

last_analyzed_at?: string

The last time the script was analyzed for Smart Placement.

formatdate-time
status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
Deprecatedplacement_mode?: "smart" | "targeted"
One of the following:
"smart"
"targeted"
Deprecatedplacement_status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS"
One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
tag?: string

The immutable ID of the script.

tags?: Array<string> | null

Tags associated with the Worker.

tail_consumers?: Array<ConsumerScript { service, environment, namespace } > | null

List of Workers that will consume logs from the attached Worker.

service: string

Name of Worker that is to be the consumer.

environment?: string

Optional environment if the Worker utilizes one.

namespace?: string

Optional dispatch namespace the script belongs to.

usage_model?: "standard" | "bundled" | "unbound"

Usage model for the Worker invocations.

One of the following:
"standard"
"bundled"
"unbound"

Upload Worker Module

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const script = await client.workers.scripts.update('this-is_my_script-01', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  metadata: {},
});

console.log(script.id);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "startup_time_ms": 10,
    "id": "this-is_my_script-01",
    "compatibility_date": "2021-01-01",
    "compatibility_flags": [
      "nodejs_compat"
    ],
    "created_on": "2022-05-05T05:15:11.602148Z",
    "entry_point": "index.js",
    "etag": "777f24a43bef5f69174aa69ceaf1dea67968d510a31d1vw3e49d34a0187c06d1",
    "handlers": [
      "fetch"
    ],
    "has_assets": false,
    "has_modules": false,
    "last_deployed_from": "wrangler",
    "logpush": false,
    "migration_tag": "v1",
    "modified_on": "2022-05-20T19:02:56.446492Z",
    "named_handlers": [
      {
        "handlers": [
          "class"
        ],
        "name": "MyDurableObject"
      }
    ],
    "observability": {
      "enabled": true,
      "head_sampling_rate": 0.1,
      "logs": {
        "enabled": true,
        "invocation_logs": true,
        "destinations": [
          "cloudflare"
        ],
        "head_sampling_rate": 0.1,
        "persist": true
      },
      "traces": {
        "destinations": [
          "cloudflare"
        ],
        "enabled": true,
        "head_sampling_rate": 0.1,
        "persist": true
      }
    },
    "placement": {
      "mode": "smart",
      "last_analyzed_at": "2025-01-01T00:00:00Z",
      "status": "SUCCESS"
    },
    "placement_mode": "smart",
    "placement_status": "SUCCESS",
    "tag": "e8f70fdbc8b1fb0b8ddb1af166186758",
    "tags": [
      "my-team",
      "my-public-api"
    ],
    "tail_consumers": [
      {
        "service": "my-log-consumer",
        "environment": "production",
        "namespace": "my-namespace"
      }
    ],
    "usage_model": "standard"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "startup_time_ms": 10,
    "id": "this-is_my_script-01",
    "compatibility_date": "2021-01-01",
    "compatibility_flags": [
      "nodejs_compat"
    ],
    "created_on": "2022-05-05T05:15:11.602148Z",
    "entry_point": "index.js",
    "etag": "777f24a43bef5f69174aa69ceaf1dea67968d510a31d1vw3e49d34a0187c06d1",
    "handlers": [
      "fetch"
    ],
    "has_assets": false,
    "has_modules": false,
    "last_deployed_from": "wrangler",
    "logpush": false,
    "migration_tag": "v1",
    "modified_on": "2022-05-20T19:02:56.446492Z",
    "named_handlers": [
      {
        "handlers": [
          "class"
        ],
        "name": "MyDurableObject"
      }
    ],
    "observability": {
      "enabled": true,
      "head_sampling_rate": 0.1,
      "logs": {
        "enabled": true,
        "invocation_logs": true,
        "destinations": [
          "cloudflare"
        ],
        "head_sampling_rate": 0.1,
        "persist": true
      },
      "traces": {
        "destinations": [
          "cloudflare"
        ],
        "enabled": true,
        "head_sampling_rate": 0.1,
        "persist": true
      }
    },
    "placement": {
      "mode": "smart",
      "last_analyzed_at": "2025-01-01T00:00:00Z",
      "status": "SUCCESS"
    },
    "placement_mode": "smart",
    "placement_status": "SUCCESS",
    "tag": "e8f70fdbc8b1fb0b8ddb1af166186758",
    "tags": [
      "my-team",
      "my-public-api"
    ],
    "tail_consumers": [
      {
        "service": "my-log-consumer",
        "environment": "production",
        "namespace": "my-namespace"
      }
    ],
    "usage_model": "standard"
  },
  "success": true
}