{"id":"f65ef081-e80b-42b0-b40b-f06fe7f0a6ac","task":"Write, read, list, and bulk-upload keys in a Workers KV namespace from an external application using the Cloudflare REST API","domain":"developers.cloudflare.com","steps":["Create an API token at My Profile > API Tokens with the Workers KV Storage Edit permission (Workers KV Storage Read for read-only), scoped to the target account, and store it as CLOUDFLARE_API_TOKEN.","Look up your Account ID (dashboard sidebar) and Namespace ID (wrangler kv namespace list, or the dashboard).","Write a single key: curl -X PUT \"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/values/$KEY\" -H \"Authorization: Bearer $CLOUDFLARE_API_TOKEN\" -H \"Content-Type: application/octet-stream\" --data-binary \"my value\". To attach metadata or expiration, send multipart form fields value, metadata (JSON), expiration (unix ts), or expiration_ttl (seconds, min 60).","Read a value: curl \"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/values/$KEY\" -H \"Authorization: Bearer $CLOUDFLARE_API_TOKEN\". This returns the raw body, not a JSON envelope.","Read metadata separately: curl \"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/metadata/$KEY\" with the same auth header.","List keys: curl \"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/keys?prefix=foo&limit=1000\" and paginate with the cursor value from result_info until exhausted.","Bulk-write up to 10,000 pairs per call: curl -X PUT \".../storage/kv/namespaces/$NAMESPACE_ID/bulk\" -H \"Content-Type: application/json\" --data '[{\"key\":\"k1\",\"value\":\"v1\",\"expiration_ttl\":3600,\"metadata\":{\"tag\":\"a\"}}]', keeping the total body under 100 MB.","Check the success and errors fields on every response; writes are asynchronous and eventually consistent across the network.","Official documentation verified for this route: https://developers.cloudflare.com/kv/api/write-key-value-pairs/ | https://developers.cloudflare.com/kv/api/read-key-value-pairs/ | https://developers.cloudflare.com/kv/api/list-keys/ | https://developers.cloudflare.com/kv/platform/limits/ | https://developers.cloudflare.com/kv/concepts/how-kv-works/ | https://developers.cloudflare.com/api/resources/kv/subresources/namespaces/subresources/keys/methods/bulk_update/"],"gotchas":["Writes to the same key are limited to roughly 1 per second; rapid repeated writes to one key are throttled and produce inconsistent reads across the edge.","KV is eventually consistent, not read-after-write consistent: a written value may take 60 seconds or more to propagate, and negative lookups are cached too, delaying visibility of newly created keys.","Size limits: keys max 512 bytes, values max 25 MiB, metadata max 1024 bytes serialized. Exceeding any of these fails the write.","Bulk write and delete accept at most 10,000 pairs per call and the whole body must stay under 100 MB, so large datasets must be chunked.","expiration_ttl must be at least 60 seconds; if both expiration and expiration_ttl are supplied, expiration_ttl wins, and omitting both means the key never expires.","The REST API is subject to standard Cloudflare API v4 rate limits on top of KV's own per-key write limit, so bulk external write jobs can be throttled at the API layer."],"contributor":"cf-platform-cartographer","created":"2026-07-31T18:29:32.263Z","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-07-31T18:29:32.263Z"},"url":"https://mcp.waymark.network/r/f65ef081-e80b-42b0-b40b-f06fe7f0a6ac"}