Skip to content

Cap OpenRouter max_tokens, add budget-aware retry, and improve streaming UI#11

Open
Amer-alsayed wants to merge 1 commit intomasterfrom
codex/review-ai-response-output-format-x7p5f7
Open

Cap OpenRouter max_tokens, add budget-aware retry, and improve streaming UI#11
Amer-alsayed wants to merge 1 commit intomasterfrom
codex/review-ai-response-output-format-x7p5f7

Conversation

@Amer-alsayed
Copy link
Owner

Motivation

  • Prevent OpenRouter failures caused by oversized max_tokens requests that exceed account credits and return errors like "This request requires more credits, or fewer max_tokens.".
  • Make the server-side provider call resilient by retrying with a reduced, affordable token budget when the provider signals a credit/token error.
  • Improve client-side streaming rendering to handle SSE chunk boundaries, reduce UI thrash, and enhance live code/math rendering during streaming.

Description

  • In api/chat.js replace the hardcoded max_tokens: 42000 with a configurable cap via OPENROUTER_MAX_TOKENS (default 8192) and clamp request values using a safe minimum of 256 by default.
  • Add parseBudgetFromError() and createOpenRouterCompletion() helpers and implement a budget-aware retry that detects token/credit errors and retries once with a reduced max_tokens (parsed affordable value or a smaller fallback, bounded by 4096).
  • In assets/js/app.js fix 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.
  • In assets/css/style.css add the .assistant-message-text.streaming-reveal animation and supporting @keyframes to smooth visual reveal while streaming.
  • Bump the CSS version query in index.html to force clients to pick up the updated stylesheet.

Testing

  • Ran node --check api/chat.js to validate syntax of the modified server file and it succeeded.
  • No further automated test suite was present or executed in this rollout; changes are focused on request-safety and runtime streaming behavior and should be smoke-tested in a running environment with an OpenRouter API key.

Codex Task

@vercel
Copy link

vercel bot commented Feb 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chaqgpt Ready Ready Preview, Comment Feb 17, 2026 0:10am

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant