Repository navigation
[AISAGE-756] fix(ai-gateway): strip paid server features from free requests - #8553
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe incremental commit Assumptions: Files Reviewed (5 files)
Previous Review Summaries (3 snapshots, latest commit 5fc7dd9)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 5fc7dd9)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental change ( Assumptions: Files Reviewed (2 files)
Previous review (commit b53e447)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental change ( Assumptions: Files Reviewed (2 files)
Previous review (commit 8b50747)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe free/anonymous request hardening in Assumptions: Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (3 files)
Reviewed by deepseek-flash-latest · Input: 53.2K · Output: 9.2K · Cached: 571.9K Review guidance: REVIEW.md from base branch |
Summary
Free models could trigger paid OpenRouter and Vercel features.
plugins(web search, PDF parsing with OCR) and server tools intoolspassed throughapplyProviderSpecificLogicunchanged, including for anonymous callers. OpenRouter bills those features to the gateway account even when the model is free, and usage accounting zeroes the cost of free requests.applyProviderSpecificLogicnow callsremovePaidServerFeaturesfor free models, before any other transform. Anonymous callers can only use free models, so this covers them too:response-healing,context-compression) and removes every other plugin id, so new plugins are removed by default.{ id: 'file-parser', pdf: { engine: 'cloudflare-ai' } }. Without an engine, OpenRouter parses PDFs withmistral-ocr(billed per page) for models that do not accept files natively, so removing the plugin alone would not stop OCR charges.cloudflare-aiis the free engine.type, or with typefunctionorcustom, are kept. This coversopenrouter:*tools and their aliases, such asweb_search,web_search_preview,web_search_20250305,web_fetch_*,image_generation,shellandadvisor_*. It also covers provider-hosted tools such as Responsesfile_searchandcode_interpreter. The rule keeps only known client-run tool types, so new aliases are removed without a code change.toolsif no tool is left. Removestool_choiceif no tool is left, or if it forces a removed tool type, so the upstream does not reject the request.Paid requests from signed-in users, custom LLMs and direct BYOK keep these fields unchanged.
Verification
context-compression), the forced PDF parser on OpenRouter only, tool lists with only server tools, and a forcedtool_choice.Visual Changes
N/A
Reviewer Notes
functiontools, so their tools are unchanged. A free-model client that sends a client-run built-in tool type, such as Anthropicbash_*or Responsesapply_patch, now has that tool removed. I chose this over a list of paid aliases, which would break as OpenRouter adds aliases.cloudflare-aimarkdown instead of the raw PDF.isFreeModelExcludingCustomLlms(requestedModel), the same value that setsproviderContext.isFreefor OpenRouter and Vercel requests.