Delete key-value pairs
To delete a key-value pair, call the delete()
method of the KV binding on any KV namespace you have bound to your Worker code:
env.NAMESPACE.delete(key);
Example
Section titled “Example”An example of deleting a key-value pair from within a Worker:
export default { async fetch(request, env, ctx) { try { await env.NAMESPACE.delete("first-key");
return new Response("Successful delete", { status: 200 }); } catch (e) { return new Response(e.message, {status: 500}); } },};
Reference
Section titled “Reference”The following method is provided to delete from KV:
delete()
method
Section titled “delete() method”To delete a key-value pair, call the delete()
method of the KV binding on any KV namespace you have bound to your Worker code:
env.NAMESPACE.delete(key);
Parameters
Section titled “Parameters”key
:string
- The key to associate with the value.
Response
Section titled “Response”response
:Promise<void>
- A
Promise
that resolves if the delete is successful.
- A
This method returns a promise that you should await
on to verify successful deletion. Calling delete()
on a non-existing key is returned as a successful delete.
Calling the delete()
method will remove the key and value from your KV namespace. As with any operations, it may take some time for the key to be deleted from various points in the Cloudflare global network.
Guidance
Section titled “Guidance”Delete data in bulk
Section titled “Delete data in bulk”Delete more than one key-value pair at a time with Wrangler or via the REST API.
The bulk REST API can accept up to 10,000 KV pairs at once. Bulk writes are not supported using the KV binding.
Other methods to access KV
Section titled “Other methods to access KV”You can also delete key-value pairs from the command line with Wrangler or with the REST API.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark