Skip to content
Source
Sign inSign up
TanStack/schemas

FAL pricing extract: Claude Sonnet 5.5 through Cloudflare AI Gateway (#550) #551

Mergedtombeckenhammerged 5 commits intomain fromrefs/pull/551/headmerged by tombeckenham View on GitHub

tombeckenhamcommented

Closes #550.

FAL leftover-section extraction now runs on Claude Sonnet 5.5 through Cloudflare AI Gateway (Unified Billing). It no longer uses grokChat and XAI_API_KEY.

Wiring

  • gatewayChat (src/server/ingest/extract-fal-pricing.ts) uses TanStack AI chat() with createAnthropicChat from @tanstack/ai-anthropic, and its fetch is cloudflareBindingFetch({ binding: env.AI, vendor: 'anthropic', gateway: { id } }) from @tanstack/ai-cloudflare. Gateway auth comes from the binding, so no provider key is needed.
  • wrangler.jsonc adds the ai binding (AI) and the AI_GATEWAY_ID var (modelschemas). worker-configuration.d.ts is regenerated.
  • The logic is unchanged: one repair turn on the same model, no fallback chain, and a failed row still rewinds the cursor. Without the binding or the gateway id, leftovers are skipped, with the same message as before but naming the new config.
  • @tanstack/ai moves to 1.0.1, plus @tanstack/ai-anthropic 1.0.0 and @tanstack/ai-cloudflare 1.0.0. An overrides entry keeps a single @cloudflare/workers-types 5, so env.AI needs no cast.
  • No temperature is sent: Claude 5 models return a 400 for it (anthropic-features.ts already records this).

Model comparison

scripts/compare-fal-extract-models.ts runs the production prompt EXTRACT_SYSTEM, the checkExtractedCard/verifyExamples checks and the repair turn over 30 live FAL Pricing sections: 17 sections that have hand-checked fixture cards plus 13 sampled leftovers. A card counts as a hand-card match when it reproduces every example price on the fixture to within 1%. Calls used Doppler dev keys. Cost per page is the provider list price, which the gateway passes through, before the Unified Billing fee.

ModelPassHand-card matchRepair turnsCost / pageMedian latency
claude-sonnet-5-530/309/171/30$0.00765.6s
claude-haiku-5-529/309/174/29$0.00096.6s
gpt-6-luna¹28/303/179/28$0.000611.0s
grok-4.7¹————~99s (stopped at 3/30)

¹ Run through the earlier OpenAI-compatible adapter path, using the same prompt and checks.

Gemini 3.8 Flash was not scored. The dev key is on the free tier: its 20 requests/day were used up, and the remaining calls hit 503 "high demand" errors.

Why Sonnet: it is the only model that passed every page. It needed the fewest repairs and was the fastest. At roughly $0.008 per leftover page the hourly cron costs cents. Haiku matches it on hand-card accuracy at about 1/8 of the cost, but it failed one page and needed 4× the repairs. To switch, change FAL_PRICING_EXTRACT_MODEL.

Hand-card mismatches are the same 8 for both Claude models. They come from fixture/input shape, not from extraction mistakes:

  • gpt-image cards are token-priced in the fixtures.
  • MiniMax uses an enum case (768P vs 768p).
  • Seedance reference-to-video bills input video tokens. These cards pass verifyExamples against the section's own examples.

Before this works in prod

  • Create the modelschemas gateway with Unified Billing and load credits. This was out of scope for the PR. Until then, leftovers fail and the cursor rewinds.
  • Watch the first hourly run (06:00 UTC) for gateway errors.
  • XAI_API_KEY stays: the xAI provider poll still uses it.
    1. cloudflare-workers-and-pages[bot](GitHub profile, opens in a new tab)commented

      Deploying with  Cloudflare Workers  Cloudflare Workers

      The latest updates on your project. Learn more about integrating Git with Workers.

      StatusNameLatest CommitUpdated (UTC)
      ✅ Deployment successful!
      View logs
      modelschemas21ddd1e9Oct 31 2026, 10:39 AM
    2. tombeckenham merged this272ed8f

    3. tombeckenham closed this

Sign in to join this conversation.