Repository navigation
fix(volumes): ask DataForSEO once per brand instead of once per prompt - #749
Merged
Merged
Conversation
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.
This was referenced Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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_usagerecords 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/refreshtakes the same path and never calls the LLM, so a refresh is now a single request end to end.Three consequences worth stating plainly:
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.google_volumesis 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 fixHow to test
brand volume lookup complete. Expected:dataforseoRequests: 1for any brand up to 200 prompts. Previously this would have been one request per prompt.Verification already done
yarn lint,yarn format:checkandyarn testpass fromserver/. 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
feature/,fix/,chore/,docs/)yarn lintpasses (run fromweb/) — no web changes in this PRyarn typecheckpasses (run fromweb/) — no web changes in this PRyarn format:checkpasses (run fromweb/) — no web changes in this PR