Skip to content

fix(volumes): ask DataForSEO once per brand instead of once per prompt - #749

Merged
gkhngyk merged 1 commit into
mainfrom
feature/dataforseo-batch-keywords
Aug 20, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/dataforseo-batch-keywords

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

We were paying roughly 100× more than necessary for search volume data.

DataForSEO bills per request, not per keyword. One request to the live Google Ads Search Volume endpoint carries up to 1000 keywords, and their docs are explicit that "the price for 1 or 1000 keywords will be the same" — $0.09 per request on the live method we use.

We sent one request per prompt, with exactly five keywords in it. So:

Prompts Requests today Cost today Cost batched
1 1 $0.09 $0.09
50 50 $4.50 $0.09
100 100 $9.00 $0.09

At five keywords per prompt, one request covers 200 prompts. Every brand under that size is now a single request.

This matches the account. Lifetime spend is $178.21 ($501 loaded, $322.79 left). volume_usage records 1,441 prompts analyzed; at $0.09 each that is $129.69, and the remaining $48.52 is GSC keyword suggestions plus development testing. So ~$130 was spent where ~$9 would have done.

What changed

Keyword extraction stays per prompt — it is an LLM call and cannot be shared. The lookup now happens once for the whole set, chunked at the documented 1000-keyword ceiling. POST /api/volumes/refresh takes the same path and never calls the LLM, so a refresh is now a single request end to end.

Three consequences worth stating plainly:

  • The request is now retried (3 attempts, existing withRetry). It never was before. One request now stands in for up to 200 prompts, so losing it to a blip costs far more than it used to.
  • A lookup failure now fails every prompt it covered. Previously a failed call cost one prompt. This is a real trade for the saving, and it is written in the code rather than left to be discovered.
  • Each prompt reads only its own keywords out of a map that now holds the whole brand's, where it previously consumed the entire response. Lookups are case-folded because the response echoes keywords in its own normalised form; the stored key stays the returned one, so google_volumes is byte-for-byte what it was.

The run now logs its phases separately (keywordMs, lookupMs, writeMs, dataforseoRequests) so the next run answers how long this takes instead of leaving it to be estimated.

Related issue

None — found while costing out the run this endpoint had just been fixed to allow.

Type of change

  • fix — Bug fix

How to test

  1. Run volume analysis on a brand with more than one unanalyzed prompt.
  2. Check the server log for brand volume lookup complete. Expected: dataforseoRequests: 1 for any brand up to 200 prompts. Previously this would have been one request per prompt.
  3. Confirm the DataForSEO account balance moves by $0.09, not by $0.09 × prompt count.
  4. Check the Prompts table: volumes, competition and estimated AI volume should be what they were before — each prompt keyed to its own keywords, not the brand's total.
  5. Click Refresh Volumes. Expected: one request, no LLM calls, same numbers.

Verification already done

  • 348 server tests pass (was 344). 12 new tests covering the batching itself.
  • Mutation-checked, not just run: reverting the batch to a per-prompt lookup fails 5 of them, including the two that pin the request count.
  • Pricing confirmed from DataForSEO's own documentation and pricing pages, then cross-checked against our real account balance and usage history as above.
  • Per-prompt attribution is pinned by a test where two prompts with different keywords must come back with 100 and 7 — not 107 each, which is what consuming the shared response would produce.
  • yarn lint, yarn format:check and yarn test pass from server/. No web files are touched by this PR.

Not covered: no real DataForSEO call was made — that spends money, and the request-count assertions are what the bill is made of.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/)
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — no web changes in this PR
  • yarn typecheck passes (run from web/) — no web changes in this PR
  • yarn format:check passes (run from web/) — no web changes in this PR
  • Changes are focused — one concern per PR

DataForSEO bills per request, not per keyword: one request carries up to 1000
keywords, and a request for five costs exactly what a request for a thousand
costs — $0.09 on the live endpoint we use. We sent one request per prompt with
exactly five keywords in it, so a 100-prompt brand paid $9.00 to do the work a
single $0.09 request covers.

Across the 1,441 prompts analyzed to date that is roughly $130 spent where ~$9
would have done, and it matches the account: $178 of lifetime spend against
$130 attributable to these calls, the rest being GSC suggestions and testing.

Keyword extraction stays per prompt — it is an LLM call and cannot be shared —
but the lookup now happens once for the whole set, chunked at the documented
1000-keyword ceiling. Refresh takes the same path; it never calls the LLM, so
it is now a single request end to end.

Two things follow from one request standing in for up to 200 prompts. It is
retried before being given up on, which it never was before. And when it does
fail it fails every prompt it covered, where previously a blip cost one prompt
— stated in the code because it is a real trade for the saving.

Each prompt now reads its own keywords out of a map holding the whole brand's,
rather than consuming the whole response as before. Lookups are case-folded,
since the response echoes keywords in its own normalised form, and the stored
key stays the returned one so google_volumes is unchanged.

The run logs its phases separately, so the next one answers how long this takes
instead of leaving it to be guessed.
@gkhngyk
gkhngyk merged commit 080f47f into main Aug 20, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/dataforseo-batch-keywords branch August 20, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant