Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/bindings/README.md
1# Cloudflare Bindings Skill Reference23Expert guidance on Cloudflare Workers Bindings - the runtime APIs that connect Workers to Cloudflare platform resources.45## What Are Bindings?67Bindings are how Workers access Cloudflare resources (storage, compute, services) via the `env` object. They're configured in `wrangler.jsonc`, type-safe via TypeScript, and zero-overhead at runtime.89## Reading Order10111. **This file** - Binding catalog and selection guide122. **[api.md](api.md)** - TypeScript types and env access patterns133. **[configuration.md](configuration.md)** - Complete wrangler.jsonc examples144. **[patterns.md](patterns.md)** - Best practices and common patterns155. **[gotchas.md](gotchas.md)** - Critical pitfalls and troubleshooting1617## Binding Catalog1819### Storage Bindings2021| Binding | Use Case | Access Pattern |22|---------|----------|----------------|23| **KV** | Key-value cache, CDN-backed reads | `env.MY_KV.get(key)` |24| **R2** | Object storage (S3-compatible) | `env.MY_BUCKET.get(key)` |25| **D1** | SQL database (SQLite) | `env.DB.prepare(sql).all()` |26| **Durable Objects** | Coordination, real-time state | `env.MY_DO.get(id)` |27| **Vectorize** | Vector embeddings search | `env.VECTORIZE.query(vector)` |28| **Queues** | Async message processing | `env.MY_QUEUE.send(msg)` |2930### Compute Bindings3132| Binding | Use Case | Access Pattern |33|---------|----------|----------------|34| **Service** | Worker-to-Worker RPC | `env.MY_SERVICE.fetch(req)` |35| **Workers AI** | LLM inference | `env.AI.run(model, input)` |36| **Browser Rendering** | Headless Chrome | `env.BROWSER.fetch(url)` |3738### Platform Bindings3940| Binding | Use Case | Access Pattern |41|---------|----------|----------------|42| **Analytics Engine** | Custom metrics | `env.ANALYTICS.writeDataPoint(data)` |43| **mTLS** | Client certificates | `env.MY_CERT` (string) |44| **Hyperdrive** | Database pooling | `env.HYPERDRIVE.connectionString` |45| **Rate Limiting** | Request throttling | `env.RATE_LIMITER.limit(id)` |46| **Workflows** | Long-running workflows | `env.MY_WORKFLOW.create()` |4748### Configuration Bindings4950| Binding | Use Case | Access Pattern |51|---------|----------|----------------|52| **Environment Variables** | Non-sensitive config | `env.API_URL` (string) |53| **Secrets** | Sensitive values | `env.API_KEY` (string) |54| **Text/Data Blobs** | Static files | `env.MY_BLOB` (string) |55| **WASM** | WebAssembly modules | `env.MY_WASM` (WebAssembly.Module) |5657## Quick Selection Guide5859**Need persistent storage?**60- Key-value < 25MB → **KV**61- Files/objects → **R2**62- Relational data → **D1**63- Real-time coordination → **Durable Objects**6465**Need AI/compute?**66- LLM inference → **Workers AI**67- Scraping/PDFs → **Browser Rendering**68- Call another Worker → **Service binding**6970**Need async processing?**71- Background jobs → **Queues**7273**Need config?**74- Public values → **Environment Variables**75- Secrets → **Secrets** (never commit)7677## Quick Start78791. **Add binding to wrangler.jsonc:**80```jsonc81{82"kv_namespaces": [83{ "binding": "MY_KV", "id": "your-kv-id" }84]85}86```87882. **Generate types:**89```bash90npx wrangler types91```92933. **Access in Worker:**94```typescript95export default {96async fetch(request, env, ctx) {97await env.MY_KV.put('key', 'value');98return new Response('OK');99}100}101```102103## Type Safety104105Bindings are fully typed via `wrangler types`. See [api.md](api.md) for details.106107## Limits108109- 64 bindings max per Worker (all types combined)110- See [gotchas.md](gotchas.md) for per-binding limits111112## Key Concepts113114**Zero-overhead access:** Bindings compiled into Worker, no network calls to access115**Type-safe:** Full TypeScript support via `wrangler types`116**Per-environment:** Different IDs for dev/staging/production117**Secrets vs Vars:** Secrets encrypted at rest, never in config files118119## See Also120121- [Cloudflare Docs: Bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/)122- [Wrangler Configuration](https://developers.cloudflare.com/workers/wrangler/configuration/)123