Backend-aware advice in HTTP errors: key variable, 402, Retry-After - #14
Merged
Merged
Conversation
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.
What and why
HTTP error advice always said
Check TYPESAFE_API_KEY., even when the client talked to OpenRouter, where the key comes fromOPENROUTER_API_KEY. A 402 fell through to the generic "try again later" text, and a 429 ignored the server'sRetry-Afterheader. The advice now matches the backend that was called.Change
safeError(error, backend?)takes an optional backend name or config. The client passes its backend fromevaluate()andlistModels().Check <keyEnv>.for the backend's key variable (OPENROUTER_API_KEYon OpenRouter). Without a backend, the text staysCheck TYPESAFE_API_KEY..Insufficient credits. Add credits at https://openrouter.ai/credits.on OpenRouter,Check your account balance.elsewhere. A 402 does not mark the key unusable.Retry after <n> seconds.when the response carries a numericRetry-After. Dates, blanks, and other values are ignored, so the message quotes no other header content.docs/api.mdandCHANGELOG.mdupdated.Verification
npm ciandnpm run checkpass: build, typecheck, 102 offline tests (2 new). The base branch passes its 100.fetchon both backends: 401, 402, and 429 with and withoutRetry-After: 7. They assert the exact messages, thatusableis false after a 401 and true after a 402, and that no upstream body reaches a message.Live testing is not applicable: the transport and response validation are unchanged; only the text of error messages changes.
Compatibility and release notes
backendparameter is optional, and one-argumentsafeErrorcalls return the same messages as before for 401 and 429 withoutRetry-After.