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
iLearn
iLearnOP6d ago
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 .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:
const value = await env.NAMESPACE.list({ prefix: "user:1:" });
// Suppose this returns 50 keys
const value = await env.NAMESPACE.list({ prefix: "user:1:" });
// Suppose this returns 50 keys
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.
Walshy
Walshy6d ago
Cloudflare Docs
Pricing · Cloudflare Workers KV
Workers KV is included in both the Free and Paid Workers plans.
iLearn
iLearnOP6d ago
this link doesnot have the answer. Pease read my Q carefully.
Walshy
Walshy6d ago
It does answer
List requests 1,000 / day 1 million/month, + $5.00/million
It bills on a list request, of which it's $5 per million Not per key
iLearn
iLearnOP6d ago
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 ?
Walshy
Walshy6d ago
Again, it bills per list request as per the docs.
iLearn
iLearnOP6d ago
Thanks. Is there a programmatic way to verify this ?
Walshy
Walshy6d ago
Send some requests and then query graphql list requests i guess? https://cfdata.lol/graphql/#AccountKvOperationsAdaptiveGroups
iLearn
iLearnOP6d ago
Thanks. Will try this.
thomasgauvin
thomasgauvin5d ago
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.

Did you find this page helpful?