Query D1
Runs statements on the host that holds the app’s database. With only data:read the database is opened
read-only (a write is refused); changing data needs data:write. Up to 100 statements, 4 MiB of SQL, 100 bound
parameters per statement. transaction defaults to true (all or nothing). A first-filter guard refuses
ATTACH, PRAGMA (except introspection), load_extension and transaction control. This route is audited
(no SQL text is stored) and counts against the data-route limits.
/v1/apps/{project}/d1/{binding}/queryAuthorizationBearer token · headerrequiredA team API key, sbk_..., from Settings, API keys.
x-api-keyAPI key · headerrequiredThe same key, in a header of its own.
projectstringrequiredThe app's name, unique within the team. 3 to 51 characters (or 1), lowercase letters, digits and dashes, not starting or ending with a dash.
bindingstringrequiredThe D1 binding name from the app's config, for example DB.
application/jsonstatementsobject[]requiredShow propertiesHide properties
objectsqlstringrequiredparamsstring | number | boolean[]transactionbooleanOne result per statement, in the shape of Cloudflare's D1 REST API.
resultsobject[]Show propertiesHide properties
objectsuccessbooleanresultsobject[]metaobjectThe request is malformed (invalid), a statement is refused (refused) or SQLite failed it (sql-error, with statement).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredinvaliderrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredrefusederrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredsql-errorstatementintegerThe index of the failing statement in statements.
errorstringrequiredA message for people. Do not parse it.
reasonstringA stable, machine-readable cause, when there is one.
pathstringThe request field at fault.
needstringThe grant a 403 asks for, app:write for example.
retry_after_sintegerNo key, or an invalid, expired or revoked key (unknown or missing API token, invalid, expired or revoked API key). No reason.
errorstringrequiredA message for people. Do not parse it.
reasonstringA stable, machine-readable cause, when there is one.
pathstringThe request field at fault.
needstringThe grant a 403 asks for, app:write for example.
retry_after_sintegerThe key lacks a grant (reason: forbidden, need: "<resource>:<action>").
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredforbiddenneedstringrequiredThe grant, as <resource>:<action>, for example app:write.
No such app (message only), database (no-database), bucket (no-bucket) or object (no-object).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredno-databaseerrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredno-bucketerrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredno-objecterrorstringrequiredA message for people. Do not parse it.
reasonstringA stable, machine-readable cause, when there is one.
pathstringThe request field at fault.
needstringThe grant a 403 asks for, app:write for example.
retry_after_sintegerD1: remote writes are off for this database (capture-active), or its file is unusable (bad-database).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredcapture-activeerrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredbad-databaseThe request is over the limit (too-large) or the result is over 8 MiB (result-too-large).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredtoo-largeerrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredresult-too-largeerrorstringrequiredA message for people. Do not parse it.
reasonstringA stable, machine-readable cause, when there is one.
pathstringThe request field at fault.
needstringThe grant a 403 asks for, app:write for example.
retry_after_sintegerThe statement needs more memory than the host allows (reason: memory-limit).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredmemory-limitData routes: too many requests in flight or an empty bucket (rate; note retry_after, without _s), or key-rate-limited. Honor Retry-After.
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredkey-rate-limitedretry_after_sintegerrequiredSeconds to wait; also the Retry-After header.
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredrateretry_afterintegerrequiredSeconds to wait; also the Retry-After header.
The host agent answered something the Cloud could not handle (reason: agent-error).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredagent-errorThe app's host is not reachable (host-unavailable), is busy with the app's data (busy, Retry-After), or the audit log could not record the request (audit-unavailable). Retry shortly.
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredhost-unavailableerrorstringrequiredA message for people. Do not parse it.
reasonstringrequiredbusyretry_afterintegerrequiredSeconds to wait; also the Retry-After header.
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredaudit-unavailableThe host did not answer in time (reason: timeout). committed says whether a write may have been applied.
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredtimeoutcommittedstringrequirednounknownThe app's storage quota on its host is full (reason: quota-exceeded).
errorstringrequiredA message for people. Do not parse it.
reasonstringrequiredquota-exceeded