Cloudflare - v1.3.0
    Preparing search index...

    Interface CloudflareEnv

    The Cloudflare half of a Worker environment: one member per platform resource that can be bound to a Worker.

    Everything here is a Cloudflare type from @cloudflare/workers-types, bound by declaring the resource in wrangler.json. The names are the conventional ones this package defaults to; the types are the platform's.

    A consuming Worker extends this with its own variables and secrets:

    // src/types/Env.ts in the consuming Worker
    export interface Env extends CloudflareEnv {
    LOG_LEVEL?: string
    API_AUTH_TOKEN_HEADER: string
    API_AUTH_TOKEN_VALUE: string
    }

    This was an ambient global interface Env while it lived in the boilerplate, merged into by declaring the same name. That works in one repository and not across a package boundary — a published package cannot reliably merge into a consumer's global scope, and two packages trying it would collide. Extending an exported interface gives the same combined type without any of that.

    Every member is optional, widened from the boilerplate's required TELEMETRY, AI, and KV. A library cannot know which resources a Worker provisioned, and every accessor already looks its binding up by configured name and reports absence through isBound. Requiring anything here would reject legitimate Workers without making a single lookup safer.

    A Worker binding a resource under a non-conventional name still satisfies this, and points the configuration layer at its own name.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    interface CloudflareEnv {
        AI?: Ai;
        AI_SEARCH?: AiSearchInstance;
        AI_SEARCH_NAMESPACE?: AiSearchNamespace;
        BROWSER?: Fetcher;
        BUCKET?: R2Bucket;
        DB?: D1Database;
        DO?: DurableObjectNamespace;
        FLAGS?: Flagship;
        HYPERDRIVE?: Hyperdrive;
        KV?: KVNamespace;
        LOG_FIELDS?: string;
        LOG_LEVEL?: string;
        PIPELINE?: Pipeline;
        QUEUE?: Queue;
        RATE_LIMITER?: RateLimit;
        SERVICE_NAME?: string;
        TELEMETRY?: AnalyticsEngineDataset;
        VECTORIZE?: Vectorize;
        VPC_NETWORK?: VpcNetwork;
        VPC_SERVICE?: Fetcher;
        WORKFLOW?: Workflow;
    }
    Index
    AI?: Ai

    Cloudflare AI binding. Provides access to AI models for language processing or other AI tasks.

    AI_SEARCH?: AiSearchInstance

    Cloudflare AI Search binding, scoped to one instance. Managed retrieval over an indexed corpus — ask it a question in words and it answers with passages, or with prose grounded in them.

    Declare it under ai_search in wrangler.json to enable it. That entry also names the instance_name, which must exist at deploy time.

    AI_SEARCH_NAMESPACE?: AiSearchNamespace

    Cloudflare AI Search binding, scoped to a namespace. Opens every instance in one namespace, so a request can name the instance rather than the deployment fixing it — a corpus per tenant, created as tenants arrive.

    Declare it under ai_search_namespaces in wrangler.json to enable it.

    BROWSER?: Fetcher

    Cloudflare Browser Rendering binding. A headless browser, reached through a browser automation library.

    Declare it under browser in wrangler.json to enable it.

    BUCKET?: R2Bucket

    Cloudflare R2 binding. Object storage used for files and blobs.

    Declare it under r2_buckets in wrangler.json to enable it.

    DB?: D1Database

    Cloudflare D1 binding. Serverless SQL database used for relational data.

    Declare it under d1_databases in wrangler.json to enable it.

    DO?: DurableObjectNamespace

    Cloudflare Durable Object namespace binding. Provides strongly consistent, stateful coordination.

    Declare it under durable_objects.bindings in wrangler.json to enable it.

    FLAGS?: Flagship

    Cloudflare Flagship binding. Evaluates a feature flag at request time, so a value that would otherwise be a vars entry can be moved by a targeting rule instead of a deploy.

    Declare it under flagship in wrangler.json to enable it. That entry also names the app_id the flags are read from, so a Worker reading two apps declares two bindings.

    HYPERDRIVE?: Hyperdrive

    Cloudflare Hyperdrive binding. Pools and caches connections to an external SQL database.

    Declare it under hyperdrive in wrangler.json to enable it.

    KV?: KVNamespace

    Cloudflare KV binding. Used for storing and retrieving key-value data.

    LOG_FIELDS?: string

    Which ambient fields a log line carries, as a comma-separated list.

    Overrides logging.fields from cloudflareDefaults, which already narrows the line to what Cloudflare does not record on its own. Set it when this Worker needs a different answer:

    {
    "vars": { "LOG_FIELDS": "requestId,method,path,ip,status,service" }
    }

    A deployment whose lines leave the Workers Logs console — Logpush, an OTel export, a file — should add service. One investigating where traffic lands should add colo and country. * keeps every field; "" keeps none, leaving the level, the event and the message.

    Names ambient fields only. What a call site passes to a single log call is always emitted, because someone chose to log it.

    LOG_LEVEL?: string

    Severity threshold for this deployment, from vars in wrangler.json.

    One of the two members here that are not bindings, and both earn the exception by being what this package's own code reads. Anything in src/ that logs — the request middleware, an accessor reporting a degraded resource — hands the Env it was given straight to Logger.fromEnv, and the kernel asks for exactly this shape. Leaving each Worker to redeclare them would make that call un-typeable from a generic E extends CloudflareEnv.

    Absent or unrecognised leaves the configured threshold in force, so a Worker that never sets it behaves as it did before.

    PIPELINE?: Pipeline

    Cloudflare Pipelines binding. Takes structured records and lands them in R2 as batched files, on a schedule and in a format configured on the pipeline rather than by the Worker sending to it.

    Declare it under pipelines in wrangler.json to enable it.

    QUEUE?: Queue

    Cloudflare Queues producer binding. Used to enqueue messages for asynchronous processing.

    Declare it under queues.producers in wrangler.json to enable it.

    RATE_LIMITER?: RateLimit

    Cloudflare rate limiting binding. Counts requests against a key and reports whether one is within the rate.

    The rate and window are fixed in wrangler.json rather than passed at runtime, so a Worker needing two different rates declares two bindings. Enforced per Cloudflare location and eventually consistent — an abuse control, never an accounting record.

    Declare it under ratelimits in wrangler.json to enable it.

    SERVICE_NAME?: string

    Name stamped on every log line this Worker writes, from vars in wrangler.json.

    Declared beside the Worker's own name in the same file, on purpose: the risk of a name in two places is that they drift, and keeping both in wrangler.json means a rename that misses one is visible in the same diff.

    {
    "name": "example-worker",
    "vars": { "SERVICE_NAME": "example-worker", "LOG_LEVEL": "info" }
    }

    Cloudflare records the script name on every log record itself, so the default field list leaves service off the line — see LOG_FIELDS. This still supplies the value whenever it is asked for, and it is what a line carries once it leaves the Workers Logs console.

    Absent, Logger falls back to logging.service on the configuration surface, and then to unknown.

    TELEMETRY?: AnalyticsEngineDataset

    Cloudflare Analytics Engine binding. Used to log analytics data such as usage metrics or custom events.

    VECTORIZE?: Vectorize

    Cloudflare Vectorize binding. Vector index used for embeddings and similarity search.

    Declare it under vectorize in wrangler.json to enable it.

    VPC_NETWORK?: VpcNetwork

    Cloudflare Workers VPC binding, scoped to a private network. Reaches anything on the bound Cloudflare Tunnel or Cloudflare Mesh, with each call naming its own destination — so prefer VPC_SERVICE wherever a single endpoint will do.

    Declare it under vpc_networks in wrangler.json to enable it.

    VPC_SERVICE?: Fetcher

    Cloudflare Workers VPC binding, scoped to one private service. Reaches a single host and port on a private network through a Cloudflare Tunnel, with nothing exposed to the internet.

    Declare it under vpc_services in wrangler.json to enable it. That entry names the service_id, which fixes the destination at deploy time.

    WORKFLOW?: Workflow

    Cloudflare Workflows binding. Durable execution — a run of steps that survives restarts and retries a failed step without replaying the ones before it.

    Declare it under workflows in wrangler.json to enable it. That entry also names the exported WorkflowEntrypoint class the instances run, the same way a Durable Object binding names its class_name.