Cloudflare D1 API
Cloudflare D1 API
Cloudflare D1 is Cloudflare globally distributed SQLite — millisecond access within Workers, global read replicas, SQL-compatible, generous free tier.
Zero network latency within Workers
Optimal only within Cloudflare Workers (external access via HTTP API)
wrangler CLI: wrangler d1 create my-database. Configure D1 binding in wrangler.toml. In Workers: env.DB.prepare("SELECT * FROM users").all()
Uptime · 30-day window
About this API
D1 is Cloudflare's globally distributed SQLite database launched 2022, the relational DB part of Cloudflare's full-stack platform (Workers + R2 + KV + Durable Objects + D1 + Queues). Design core: (1) Based on SQLite (small, fast, single file); (2) Global read replicas (writes to primary region, reads distributed globally, app latency follows users); (3) Deep Cloudflare Workers integration (Worker-to-D1 call has no HTTP hop). vs. Turso: D1 is Cloudflare-exclusive (optimal only within Workers), Turso is cross-platform. vs. Vercel Postgres (Neon-based): D1 SQLite vs. Vercel Postgres. Generous free tier (100k reads + 50k writes/day), hobby / small SaaS perfectly sufficient. Cloudflare customers use D1 with Workers to build "zero cold-start + global < 50ms" apps.
What you can build
- 1Cloudflare Workers application DB
- 2Global users low-latency reads (per-region local replica)
- 3Small SaaS / blog / SaaS dashboard backend
- 4Serverless app SQL data storage
Strengths & limitations
Strengths
- Zero network latency within Workers
- Auto global read replicas
- Generous free tier (100k reads + 50k writes/day)
- Familiar SQL (SQLite-compatible)
Limitations
- Optimal only within Cloudflare Workers (external access via HTTP API)
- SQLite limitations (not for ultra-high concurrent writes)
- 10GB per DB limit
Example request
curl https://developers.cloudflare.com/d1/<endpoint> \
-H "Authorization: Bearer $API_KEY"
# Some providers use X-Api-Key instead — verify in the docs.Getting started
wrangler CLI: wrangler d1 create my-database. Configure D1 binding in wrangler.toml. In Workers: env.DB.prepare("SELECT * FROM users").all()
FAQ
D1 vs. Cloudflare KV?+
KV is simple key-value cache. D1 is real SQL DB (relations, JOINs, transactions).
Can D1 be used outside Workers?+
Yes via HTTP REST API, but latency is an order of magnitude higher than in-Worker direct calls.
Technical details
- Auth type
- api_key
- Pricing
- freemium
- Rate limit
- 免费 100k reads + 50k writes/天
- Protocols
- REST, SQL
- SDKs
- javascript, typescript