Skip to content
Source
Sign inSign up
TanStack/schemas

FAL pricing: move extraction to Cloudflare AI Gateway and pick the model by comparison #550

Closedtombeckenham opened this issue 0 comments
tombeckenhamcommented

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 to env.AI.run(model, input, { gateway: { id } }) or /ai/v1/chat/completions if the adapter lacks JSON output or temperature: 0.
  • Add the AI binding and gateway id in wrangler.jsonc, run bun run types.
  • Remove the XAI_API_KEY dependency 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).

  1. tombeckenham closed this

Sign in to join this conversation.