FAL pricing extract: Claude Sonnet 5.5 through Cloudflare AI Gateway (#550) #551
main fromrefs/pull/551/head·merged by tombeckenham View on GitHubCloses #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 AIchat()withcreateAnthropicChatfrom@tanstack/ai-anthropic, and itsfetchiscloudflareBindingFetch({ binding: env.AI, vendor: 'anthropic', gateway: { id } })from@tanstack/ai-cloudflare. Gateway auth comes from the binding, so no provider key is needed.wrangler.jsoncadds theaibinding (AI) and theAI_GATEWAY_IDvar (modelschemas).worker-configuration.d.tsis 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/aimoves to 1.0.1, plus@tanstack/ai-anthropic1.0.0 and@tanstack/ai-cloudflare1.0.0. Anoverridesentry keeps a single@cloudflare/workers-types5, soenv.AIneeds no cast.- No temperature is sent: Claude 5 models return a 400 for it (
anthropic-features.tsalready 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.
| Model | Pass | Hand-card match | Repair turns | Cost / page | Median latency |
|---|---|---|---|---|---|
| claude-sonnet-5-5 | 30/30 | 9/17 | 1/30 | $0.0076 | 5.6s |
| claude-haiku-5-5 | 29/30 | 9/17 | 4/29 | $0.0009 | 6.6s |
| gpt-6-luna¹ | 28/30 | 3/17 | 9/28 | $0.0006 | 11.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 (
768Pvs768p). - Seedance reference-to-video bills input video tokens.
These cards pass
verifyExamplesagainst the section's own examples.
Before this works in prod#
- Create the
modelschemasgateway 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_KEYstays: the xAI provider poll still uses it.
- 1
tombeckenham merged this272ed8f
tombeckenham closed this
Sign in to join this conversation.
Deploying with
Cloudflare Workers#
The latest updates on your project. Learn more about integrating Git with Workers.
View logs