FAL pricing: move extraction to Cloudflare AI Gateway and pick the model by comparison #550
Why#
FAL pricing extraction is the service's only live AI call (grokChat in src/server/ingest/extract-fal-pricing.ts). It calls xAI directly with XAI_API_KEY. Moving it onto Cloudflare AI Gateway with Unified Billing puts every usage-based cost on the Cloudflare bill (prepaid credits, provider rates passed through, 5% fee on credit purchase), which simplifies the handover to TanStack.
grok-4-fast is not in the gateway catalog, so the model has to change anyway. Pick the replacement on evidence.
Model comparison#
Candidates: Claude Sonnet (latest), Luna, Grok 4.7, plus any other strong candidates for structured JSON extraction found by research (check what the gateway catalog actually carries).
Run each over the same FAL pricing sections, using the production prompt and checks:
- prompt:
EXTRACT_SYSTEM - accept/reject:
checkExtractedCard,verifyExamples - ground truth: hand-checked cards in
packages/rate-card/src/fixtures/
Score: pass rate, match with hand-checked cards, repair-turn rate, cost per page, latency. Keep the paid calls to a few dollars (keys from Doppler dev). Put the results table in the PR.
Wiring#
- Route the winner through the gateway. Consider the TanStack AI Cloudflare gateway adapter (
@tanstack/ai); fall back toenv.AI.run(model, input, { gateway: { id } })or/ai/v1/chat/completionsif the adapter lacks JSON output ortemperature: 0. - Add the AI binding and gateway id in
wrangler.jsonc, runbun run types. - Remove the
XAI_API_KEYdependency from this path. - Keep the existing behaviour: one repair turn on the same model, no fallback chain, failed rows rewind the cursor.
Out of scope#
Creating the gateway and loading credits in the Cloudflare account (manual, by whoever owns the account).
tombeckenham closed this
Sign in to join this conversation.