fix(gateway): reject TTS/video models in chat - #2793
Conversation
Text-to-speech models (e.g. elevenlabs/eleven-multilingual-v2) and video models are served by dedicated endpoints and have no chat base URL, so routing them through /v1/chat/completions fell through to a confusing "Provider elevenlabs requires a baseUrl" 500. Reject them early with a 400 pointing to /v1/audio/speech or /v1/videos. Image-only models stay allowed since they use the chat-completions image flow. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughThe chat-completions handler gains an early output-type guard that throws HTTP 400 when the resolved model's output does not include ChangesNon-text model rejection in chat completions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
apps/gateway/src/api.spec.ts (1)
84-86: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winDrop the historical context comment from the test body.
Line 84 through Line 86 contain narrative context that is not needed for understanding the assertion path and conflicts with the no-unnecessary-comments rule.
As per coding guidelines,
**/*.{ts,tsx,js,jsx}: "No unnecessary code comments."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/gateway/src/api.spec.ts` around lines 84 - 86, Remove the three-line comment block starting with "ElevenLabs models are speech-only" from the test body in the api.spec.ts file. This comment provides historical context about previous behavior rather than explaining the current test assertion, and therefore violates the no-unnecessary-comments rule. Delete the entire comment block that discusses the fallthrough behavior and 500 error to keep the test focused on the actual assertion being tested.Source: Coding guidelines
apps/gateway/src/chat/chat.ts (1)
1763-1768: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winRemove the verbose inline rationale block and keep code self-explanatory.
Line 1763 through Line 1768 add a long explanatory comment that mostly restates behavior already evident in the guard and test coverage. Please trim/remove it to follow repository comment policy.
As per coding guidelines,
**/*.{ts,tsx,js,jsx}: "No unnecessary code comments."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/gateway/src/chat/chat.ts` around lines 1763 - 1768, Remove the verbose multi-line comment block that begins with "Text-to-speech and video models are served by dedicated endpoints" in the chat.ts file. This lengthy rationale restates behavior that is already evident from the guard logic and test coverage, violating the repository's "No unnecessary code comments" policy. Either delete the comment entirely or replace it with a single concise line if additional context is truly needed, allowing the code logic itself to be self-explanatory.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/gateway/src/api.spec.ts`:
- Around line 84-86: Remove the three-line comment block starting with
"ElevenLabs models are speech-only" from the test body in the api.spec.ts file.
This comment provides historical context about previous behavior rather than
explaining the current test assertion, and therefore violates the
no-unnecessary-comments rule. Delete the entire comment block that discusses the
fallthrough behavior and 500 error to keep the test focused on the actual
assertion being tested.
In `@apps/gateway/src/chat/chat.ts`:
- Around line 1763-1768: Remove the verbose multi-line comment block that begins
with "Text-to-speech and video models are served by dedicated endpoints" in the
chat.ts file. This lengthy rationale restates behavior that is already evident
from the guard logic and test coverage, violating the repository's "No
unnecessary code comments" policy. Either delete the comment entirely or replace
it with a single concise line if additional context is truly needed, allowing
the code logic itself to be self-explanatory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ed700fe0-df46-478d-99e1-b9bdb849d395
📒 Files selected for processing (2)
apps/gateway/src/api.spec.tsapps/gateway/src/chat/chat.ts
What
The production error log showed:
ElevenLabs (and OpenAI TTS) models are speech-only (
output: ["audio"],speechGenerations: true) and are served by the dedicated/v1/audio/speechendpoint, which has its own provider base-URL map. They have no chat base URL, so when a request hit/v1/chat/completionswith a model likeelevenlabs/eleven-multilingual-v2, endpoint resolution fell through to thedefaultcase ingetProviderEndpointand threw a confusingrequires a baseUrl500.Fix
Add an early guard in the chat-completions handler (right after model resolution) that rejects models whose output is audio or video — they belong to dedicated endpoints — with a clear 400 pointing the caller to the right endpoint:
/v1/audio/speech/v1/videosImage-only models (e.g.
reve,grok-image) are intentionally allowed, since they are served by the chat-completions image-generation flow. This mirrors the existing convention inchat-helpers.e2e.tsthat filters out audio/video-only (but not image) models from chat e2e tests.Test
Added a unit test in
apps/gateway/src/api.spec.tsassertingelevenlabs/eleven-multilingual-v2on/v1/chat/completionsreturns 400 with a pointer to/v1/audio/speech.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
/v1/audio/speechfor audio,/v1/videosfor video).Tests