With Cloudflare remote bindings, how does a Worker using KV, D1 and a Durable Object under wrangler dev also reach the real Workers AI binding?
answer
- code local, one resource real
- a per-binding boolean
- one binding has no simulator
- some types can never be remote
- real writes, real bills
basics
~20 sKeep the Worker local and mark the AI binding remote: true; Workers AI has no local simulator, so its calls go to Cloudflare while KV, D1 and the Durable Object stay simulated. Other bindings opt in the same way; Durable Objects cannot.
solid answer
~40 sRemote bindings split execution from data: the Worker still runs in local `workerd`, and only bindings marked `"remote": true` are proxied to the deployed resource. Workers AI is special because it has no local simulator: `wrangler dev` calls Cloudflare for it anyway, warns about usage charges when `remote` is omitted, and errors if it is set to `false`, so writing `"remote": true` makes the intent explicit. KV, D1 and R2 can opt in the same way, while Durable Objects and Workflows always run locally (they can still call remote bindings), and Hyperdrive, vars, secrets and static assets always stay local. Remote calls need an authenticated Wrangler, touch real data, are billed and add latency, so point them at a staging environment's resources; `wrangler dev --local` turns them all off.
code
json · 10 lines{
"name": "rooms-api",
"main": "src/index.js",
"compatibility_date": "2026-10-10",
"ai": { "binding": "AI", "remote": true },
"kv_namespaces": [{ "binding": "SESSIONS", "id": "<namespace-id>" }],
"d1_databases": [{ "binding": "DB", "database_name": "orders", "database_id": "<database-id>" }],
"durable_objects": { "bindings": [{ "name": "ROOMS", "class_name": "Room" }] },
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["Room"] }]
}go deeper
Recall that remote: true on one binding sends just that binding's calls to Cloudflare while the Worker keeps running locally.
Explain which bindings can be remote, which are local-only, and why Workers AI calls Cloudflare even when remote is omitted.
Show the safety judgment: staging resources behind remote bindings, awareness of billing and latency, and the service-binding route to deployed Durable Objects.
Weigh a team default of local simulation with a short allow-list of remote bindings against shared staging resources, and who pays for AI usage in development.
## The scenario A team's Worker uses a KV namespace for sessions, a D1 database for orders and a Durable Object for a per-room counter. All three simulate well on a laptop. A new feature calls Workers AI, which cannot be simulated at all. The goal: keep the fast local loop for everything except the one binding that has to be real. ## How remote bindings work A **remote binding** is a binding whose operations Miniflare forwards to the deployed resource while the Worker code still runs in local `workerd`. You enable it per binding with `"remote": true` in the Wrangler configuration file: ```json { "name": "rooms-api", "main": "src/index.js", "compatibility_date": "2026-10-10", "ai": { "binding": "AI", "remote": true }, "kv_namespaces": [{ "binding": "SESSIONS", "id": "<namespace-id>" }], "d1_databases": [{ "binding": "DB", "database_name": "orders", "database_id": "<database-id>" }], "durable_objects": { "bindings": [{ "name": "ROOMS", "class_name": "Room" }] }, "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Room"] }] } ``` With this file, `env.AI.run()` reaches Cloudflare, while `env.SESSIONS`, `env.DB` and `env.ROOMS` stay simulated under `.wrangler/state`. Wrangler opens a remote proxy session at startup (it prints "Establishing remote connection..."), and the binding table it prints shows each binding's mode. ## Workers AI: always remote, made explicit Wrangler classes Workers AI as a binding that will **never have a local simulator**. That shapes the three possible settings: | `remote` on the ai binding | What wrangler dev does | |---|---| | omitted | Calls Cloudflare and warns that AI bindings "always access remote resources, and so may incur usage charges even in local dev" | | `true` | Calls Cloudflare with no warning | | `false` | Refuses to start: AI bindings do not support local development | So the answer to "how do I reach the real AI binding" is mostly "you already do"; `"remote": true` documents it and silences the warning. Vectorize and mTLS certificates have no local simulator either and expect `remote: true`. ## Step by step for this Worker 1. Add `"remote": true` to the `ai` binding and leave the KV, D1 and Durable Object bindings as they are. 2. Make sure Wrangler can authenticate: `wrangler login` on a laptop, or `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` in CI. 3. Run `wrangler dev` and read the printed binding table: AI should be the only remote entry. 4. Seed the local KV namespace and D1 database with `--local` commands, and create Durable Object state through the Worker's own routes. 5. If a second resource must be real later, give it a staging resource in `env.staging` with `remote: true` and run `wrangler dev --env staging`. ## Which bindings can be remote - **Can opt in**: KV, R2, D1, service bindings, Browser Run, Images and email sending, among others. - **Always local**: Durable Objects and Workflows. Their code runs locally, but inside them `this.env` can use remote bindings, so a local Durable Object can call the real AI binding. To reach deployed objects, call a deployed Worker through a remote service binding. - **Local-only**: Hyperdrive, `vars`, secrets, static assets, version metadata, Analytics Engine and rate limiting always use local simulations or local values. ## What remote calls cost - **Real data**: writes, deletes and updates change the targeted resource. Point remote bindings at a **staging** resource, typically in an `env.staging` block with its own IDs, and run `wrangler dev --env staging`. - **Billing**: remote operations are ordinary billed usage, AI inference included. - **Latency**: each call crosses the internet, so timings differ from both local and production. - **Authentication**: Wrangler needs a login or an API token; a Worker behind Cloudflare Access also needs Access credentials, such as a service token in CI. - **Escape hatch**: `wrangler dev --local` disables every remote binding for one run, as if each were `remote: false`; Workers AI still has no local simulation, so `--local` cannot make it work offline. ## The same switch in other tools - The **Cloudflare Vite plugin** honours `remote: true` and has a `remoteBindings` option (default `true`) to turn them all off. - **`getPlatformProxy()`** from `wrangler` takes `remoteBindings` (default `true`) for a framework dev server in Node.js. - `wrangler dev --remote` is the blunt alternative: it moves the whole Worker, Durable Objects included, onto Cloudflare and makes every binding real. ## What interviewers listen for - Execution and data are separate switches; one binding can be real while the rest stay simulated. - Workers AI is always remote, which affects cost and offline work. - Durable Objects cannot be remote bindings, and remote bindings should never target production data by accident.
- How do you stop a remote binding from writing to production data while developing?Point it at a separate resource. Put the binding in an environment block such as `env.staging` with that environment's own namespace, bucket or database ID and `remote: true`, then run `wrangler dev --env staging`. The production block keeps the production IDs and no `remote` flag, so a plain `wrangler dev` stays on local simulations and never touches production data.
- Your local Durable Object must call a deployed Durable Object; how do you wire that up?A Durable Object binding cannot be remote, so go through a Worker. Deploy a Worker that exposes the deployed class, then give the local Worker a service binding to it with `remote: true`. Calls travel local Worker, remote service binding, deployed Worker, deployed Durable Object; the local Durable Object can use that service binding too.
- Does wrangler dev --local let you develop the AI feature offline?No. `--local` disables remote bindings, but Workers AI has no local simulator, and an AI binding cannot be switched to local mode. Offline work needs the AI call behind a code path you can stub, while KV, D1 and the Durable Object keep working from their local simulations.
- Switches the whole session to wrangler dev --remote just to reach one AI binding.
- Expects remote: true on a Durable Object binding to reach deployed objects.
- Assumes Miniflare ships a local Workers AI model for offline development.
- Points remote bindings at production KV or D1 IDs during everyday development.
- Thinks remote binding calls are free because the Worker runs locally.
Assumes Wrangler 4.149: remote bindings with a per-binding remote key are generally available since Wrangler 4.36 (September 2025), replacing the earlier experimental_remote key and --x-remote-bindings flag.