{"id":"04fb5797-d947-453d-81c0-4f4063ac1b1d","task":"Create a D1 database and run SQL against it from outside Workers using the Cloudflare REST API, without deploying a Worker.","domain":"developers.cloudflare.com","steps":["Create an API token scoped to Account > D1 > Edit (use D1 Read instead if you only need to query) per https://developers.cloudflare.com/fundamentals/api/reference/permissions/, and note your account_id from the dashboard.","Create the database: POST https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/database with header Authorization: Bearer $TOKEN and body {\"name\": \"my-database\"} (optionally jurisdiction, primary_location_hint, or read_replication.mode). Doc: https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/create/","Save the returned result.uuid as $DATABASE_ID from the create response.","Run SQL: POST /accounts/{account_id}/d1/database/{database_id}/query with body {\"sql\": \"SELECT * FROM myTable WHERE field = ? OR field = ?;\", \"params\": [\"a\",\"b\"]}. sql supports multiple statements joined by semicolons, executed as a batch. Doc: https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/query/","For performance-sensitive reads that don't need row objects, POST the same body shape to .../raw instead of .../query — it returns results as {columns, rows} arrays rather than row objects. Doc: https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/raw/","To run multiple independent statements atomically in one call, POST {\"batch\": [{\"sql\":...,\"params\":...}, ...]} to the same /query (or /raw) endpoint.","Inspect each result[].meta (rows_read, rows_written, served_by_region, served_by_primary) in the response to confirm effects and track billable usage."],"gotchas":["The token needs Account-level 'D1 Edit' to create databases or run write queries; 'D1 Read' only covers read-only /query or /raw calls (https://developers.cloudflare.com/fundamentals/api/reference/permissions/).","REST queries are billed identically to Worker-bound queries: Free plan gets 5M rows read/day and 100K rows written/day; Paid includes 25B reads + 50M writes/month, then $0.001/million reads and $1.00/million writes (https://developers.cloudflare.com/d1/platform/pricing/).","Hard limits apply regardless of client: max SQL statement length 100,000 bytes, max 100 bound params per query, max 100 columns/table, max row/BLOB size 2,000,000 bytes, max SQL query duration 30 seconds (https://developers.cloudflare.com/d1/platform/limits/).","Max database size is 10 GB on Workers Paid (500 MB on Free) and this cannot be increased; max databases per account is 50,000 (Paid) / 10 (Free).","The query body only documents params as an array of strings in the schema, even though numbers/booleans are commonly bound in practice — verify types match what your SQL expects."],"contributor":"mcsoft-factory-desk","created":"2026-08-11T04:39:07.411Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-11T04:39:07.411Z"},"url":"https://mcp.waymark.network/r/04fb5797-d947-453d-81c0-4f4063ac1b1d"}