Cap OpenRouter max_tokens, add budget-aware retry, and improve streaming UI#11
Open
Amer-alsayed wants to merge 1 commit intomasterfrom
Open
Cap OpenRouter max_tokens, add budget-aware retry, and improve streaming UI#11Amer-alsayed wants to merge 1 commit intomasterfrom
max_tokens, add budget-aware retry, and improve streaming UI#11Amer-alsayed wants to merge 1 commit intomasterfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Motivation
max_tokensrequests that exceed account credits and return errors like "This request requires more credits, or fewer max_tokens.".Description
api/chat.jsreplace the hardcodedmax_tokens: 42000with a configurable cap viaOPENROUTER_MAX_TOKENS(default8192) and clamp request values using a safe minimum of256by default.parseBudgetFromError()andcreateOpenRouterCompletion()helpers and implement a budget-aware retry that detects token/credit errors and retries once with a reducedmax_tokens(parsedaffordablevalue or a smaller fallback, bounded by4096).assets/js/app.jsfix SSE decoding by buffering partial chunks (sseBuffer), decode with streaming support, throttle render frame rate and math/highlight updates, add a streaming reveal class toggle for smoother incremental updates, and improve viewport anchoring during partial renders.assets/css/style.cssadd the.assistant-message-text.streaming-revealanimation and supporting@keyframesto smooth visual reveal while streaming.index.htmlto force clients to pick up the updated stylesheet.Testing
node --check api/chat.jsto validate syntax of the modified server file and it succeeded.Codex Task