How Cloudflare KV Billing Works for .list()
Following is my Question and Answer(given by ChatGPT)
Please confirm / update the Answer given by ChatGPT. Thanks.
QUESTION :
In the following Cloudflare Worker Code to List by Prefix .. how will the billing happen ? .. billing only for the Keys which are read and correspond to prefix or billing for complete scan of the KV namespace ?
export default {
async fetch(request, env, ctx) {
const value = await env.NAMESPACE.list({ prefix: "user:1:" });
return new Response(value.keys);
},
};
ANSWER by CHATGPT :
In Cloudflare Workers, billing for KV operations depends on the specific API calls and the data retrieved. Here's how the billing works for your provided code:
1. KV List API Billing
- The
KV.list()
operation is billed based on the number of keys returned that match the prefix
filter, not the total number of keys in the namespace.
- The filtering by prefix
is handled internally by Cloudflare, so the operation scans only the relevant part of the namespace that matches the specified prefix
.
2. Breakdown of Costs
- List Operation: Each call to list()
counts as a single read operation, regardless of the number of keys returned.
- Key Retrieval: You are billed for each key returned in the value.keys
array. If the list()
operation retrieves 10 keys, it will count as 10 read operations.
3. Example Billing Scenario
- Assume NAMESPACE.list({ prefix: "user:1:" })
returns 50 keys.
- You are billed for:
- 1 list operation (base cost for calling the list()
method).
- 50 read operations (one for each key returned in the result).
4. What Is NOT Charged
- You are not billed for scanning or evaluating keys that do not match the prefix
. The filtering happens on Cloudflare's side, and only matching keys are returned and billed.
This means you are billed based on the keys matching your prefix and retrieved by the list()
operation, not for scanning the entire namespace.10 Replies
Got one more (CONFLICTING) Answer by ChatGPT (o1) :
Short Answer:
No, you won’t be separately charged for each of the 50 keys returned. You pay for the single
- You are billed for each
- If you have a lot of keys and require multiple pages (using
In your example: You would only pay for 1 Class B operation for this single
No, you won’t be separately charged for each of the 50 keys returned. You pay for the single
.list()
call (a Class B operation), regardless of how many keys it returns.
---
How Cloudflare KV Billing Works for .list()
- A .list()
operation is considered one Class B operation in KV billing.- You are billed for each
.list()
call itself, not for the number of keys it returns.- If you have a lot of keys and require multiple pages (using
cursor
), each page is another Class B operation.In your example: You would only pay for 1 Class B operation for this single
.list()
call. There is no extra charge for the fact that it returned 50 keys.Docs are best source of truth: https://developers.cloudflare.com/kv/platform/pricing/
Cloudflare Docs
Pricing · Cloudflare Workers KV
Workers KV is included in both the Free and Paid Workers plans.
this link doesnot have the answer. Pease read my Q carefully.
It does answer
List requests 1,000 / day 1 million/month, + $5.00/millionIt bills on a list request, of which it's $5 per million Not per key
My Q is simple : assume 50 keys are returned as part of .list() call, will i also be charged for 50 keys read or ONLY 1 list operation ?
Again, it bills per list request as per the docs.
Thanks. Is there a programmatic way to verify this ?
Send some requests and then query graphql list requests i guess?
https://cfdata.lol/graphql/#AccountKvOperationsAdaptiveGroups
Thanks. Will try this.
Confirming what Walshy and o1 said here. A list request returns only the keys. A single list operation (via the binding with .list() or via the REST API) is billed as 1 list operation.