Files
hermes-agent/tests/agent
kshitijk4poor ee8dd6c886 fix(agent): a credit-limited 402 retries once with the affordable output cap instead of failing as billing
OpenRouter answers a request whose max_tokens exceeds the remaining balance with
"402 ... You requested up to 65536 tokens, but can only afford 56272". The account has
credit; only the cap was too large. The main loop classified it as terminal billing and
failed the turn (or rotated off a credential that still had credit), so a request that
needed a few hundred tokens was dropped (#49769).

recover_after_classification now retries once with the output cap lowered to the affordable
budget before pool rotation, reusing the auxiliary client's _affordable_max_tokens_from_error
parse (same 64-token margin and 512-token floor) and the existing one-shot
_ephemeral_max_output_tokens seam. A second credit-limited 402 on the same call, or a body
with no parseable budget, keeps today's billing handling. Classification is unchanged.

Approach from #49785 by @tcconnally (closed unmerged), applied at the recovery layer.

Co-authored-by: Thomas Connally <51974392+tcconnally@users.noreply.github.com>
2026-10-07 06:41:07 +05:30
..