fix(ai): refresh the entitlement and retry once on a 401 from the proxy - #56
Merged
Conversation
A 401 on a Pro proxy call usually means the cached 24h entitlement just expired between alarm refreshes. Instead of surfacing an error toast, refresh the entitlement with the stored license key and retry the request once. A refresh that comes back empty (revoked license) rehydrates the entitlement store so the UI degrades to Free rather than looping. This was the last open acceptance criterion of #22 — everything else (hosted routing, entitlement header, per-env API base, quota feedback, error mapping, BYO-key direct routing, mocked-backend tests) already shipped in the entitlement/gating/QA work. Closes #22. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Closes #22. The issue's acceptance criteria were all long since shipped (hosted requests to
POST /ai/generatewith per-envAPI_BASE,X-Optia-Entitlementfor Pro /installIdfor free,quotafeeding the entitlement layer, full error mapping, BYO-key direct-to-Anthropic, mocked-backend tests) — except one: 401 → entitlement refresh, one retry. This PR adds it:runProxycatches anunauthorizedproxy error on an authenticated call, runsrefreshNow(), and retries the request exactly once with the fresh tokenrefreshNow) rehydrates the entitlement store so the UI degrades to Free instead of retrying into the same 401Testing
🤖 Generated with Claude Code