feat: emit x-fal-request-id and opt-in x-fal-billable-units on fal queue responses#270
Conversation
…eue responses fal queue status/result responses now always set x-fal-request-id, matching real fal — adapters like @tanstack/ai-fal key their billing lookup off it and previously bailed without it. A billableUnits fixture field (onFalQueue / onFalImage / onFalVideo opts, or response.billableUnits in a JSON fixture) emits x-fal-billable-units on the completed queue-result so consumers can assert their cost path and surface usage.unitsBilled on replay. Record mode captures the upstream x-fal-billable-units header during the queue walk and persists it into response.billableUnits, so recorded fixtures round-trip billing with no hand-editing.
commit: |
… comments Address PR review: - correct comments that overstated x-fal-request-id as emitted on "every" queue response (it rides status + result only, not submit/cancel/404) - soften the @tanstack/ai-fal version pin in the RawJSONResponse doc - add a billableUnits: 0 test pinning the != null / Number.isFinite guard so a truthy-check regression that drops the zero-cost header can't pass green - add record-mode tests asserting an absent or non-numeric upstream x-fal-billable-units leaves the persisted fixture (and replay) header-less
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.
Closes #269.
Problem
aimock's fal dispatcher served
queue-status/queue-resultresponses withoutx-fal-request-idorx-fal-billable-units.@tanstack/ai-fal(≥ 0.8.x) installs aconfig.fetchwrapper that reads both headers off every fal response and bails without the request-id, soresult.usage.unitsBilledalways came backundefinedon replay — no way to author a fixture that exercises a consumer's cost/billing path.Changes
x-fal-request-idis now always emitted onqueue-statusandqueue-resultresponses (including the 202 in-progress result), matching real fal.x-fal-billable-unitsrides the completed (200)queue-resultwhen a fixture opts into a billed quantity viabillableUnits— available on theonFalQueue/onFalRun/onFalImage/onFalVideobuilders ({ billableUnits }) and asresponse.billableUnitsin JSON fixtures.x-fal-billable-unitsheader during the queue walk (walkFalQueuenow returns{ body, billableUnits }) and persists it intoresponse.billableUnits, so recorded fixtures round-trip billing with no hand-editing. The legacy fal-audio walk takes the body only.Tests
response.billableUnitsFull suite green;
tsc/ eslint / prettier clean. CHANGELOG and the fal-ai docs page updated.