feat: respect Accept header for response format negotiation#290
Open
rothnic wants to merge 6 commits intodecolua:masterfrom
Open
feat: respect Accept header for response format negotiation#290rothnic wants to merge 6 commits intodecolua:masterfrom
rothnic wants to merge 6 commits intodecolua:masterfrom
Conversation
…ders Providers like Antigravity maintain separate quota buckets per model family (e.g. Claude vs Gemini). A 429 on claude-opus previously locked the entire account, preventing gemini-pro requests even though its quota was full. This adds in-memory per-model locking so that only the specific model is skipped during account selection while other models remain accessible. Changes: - Add model-aware lock tracking in auth.js (Map<connectionId:model, expiry>) - Pass model context from chat handler to auth service - Multi-bucket behavior gated to known providers (MULTI_BUCKET_PROVIDERS set) - No database schema changes — locks are in-memory and clear on restart Closes decolua#110
When models (like kimi) return JSON wrapped in markdown code blocks (\`\`\`json...\`\`\`), strip the markers before sending to client. Changes: - Add markdown stripping to streaming text_delta responses - Add markdown stripping to non-streaming Claude format responses - Translate response_format to system prompts for JSON schema/object modes - Add jsonExtractor utility for consistent markdown removal This fixes AI_APICallError: Invalid JSON response when using AI SDK generateObject with kimi models through 9router.
Makes 9router check the client's Accept header when determining whether to return streaming (SSE) or non-streaming (JSON) responses. Changes: - Check clientRawRequest.headers.accept in handleChatCore() - Return non-streaming JSON when Accept: application/json - Return SSE when Accept: text/event-stream or not specified - Only applies when body.stream is not explicitly set to true This fixes AI_APICallError: Invalid JSON response when using AI SDK with 9router, as AI SDK sends Accept: application/json but previously received SSE format responses. Fixes decolua#289
Documents why markdown stripping is needed even when using response_format with kimi models. Key finding: kimi/kimi-k2.5-thinking adds markdown code blocks despite response_format settings, but kimi/kimi-k2.5 works without markdown. Markdown stripping remains as defensive backstop.
- Move KIMI_JSON_MODE_INVESTIGATION.md to docs/investigations/ - Update .gitignore to allow docs/investigations/ tracking - Better project organization for documentation
Owner
|
Hi @rothnic, thanks for this contribution! 🙏 We've cherry-picked the core changes from this PR into our fork: What we merged:
What we skipped:
Great find on the Accept header negotiation issue — clean and minimal fix. Appreciate the work! 🎉 |
decolua
pushed a commit
that referenced
this pull request
Mar 13, 2026
- Respect Accept: application/json header to return non-streaming JSON instead of SSE, fixing AI SDK generateObject/generateText compatibility - Strip markdown code block markers (```json...```) from Claude non-streaming responses to prevent JSON parse errors Cherry-picked and adapted from PR #290 by @rothnic #290 Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
9router ignores the client's
Acceptheader when determining response format. This causes AI SDK compatibility issues where clients sendAccept: application/jsonbut receive SSE streaming responses.Closes #289
Changes
clientRawRequest.headers.acceptinhandleChatCore()Accept: application/jsonAccept: text/event-streamor header not specifiedbody.streamis not explicitly set totrueTesting
Tested with:
Related