Arm the shared cooldown for rate limits tunneled through HTTP 200

Azure is the only zero-data-retention route for the gpt-5.6 family, so
its capacity 429s arrive frequently and OpenRouter forwards them inside
an HTTP 200 envelope. Those bypassed the rate controller entirely: a
paced run kept sending a request every three seconds into a throttled
endpoint, failing row by row. An in-envelope 429 now records the same
escalating cooldown as a transport 429, so later acquisitions fail fast
until the deadline passes.
This commit is contained in:
Lars Nolden
2026-09-13 11:43:49 +02:00
parent 1b09edc692
commit 4d8a187079
3 changed files with 69 additions and 23 deletions
+6
View File
@@ -365,6 +365,12 @@ func (c *Client) complete(ctx context.Context, gate *ratelimit.Controller, r com
Code int `json:"code"`
}
_ = json.Unmarshal(envelope.Error, &detail)
if detail.Code == http.StatusTooManyRequests {
// An upstream rate limit tunneled through HTTP 200 must arm the
// same cooldown as a transport 429: later Acquire calls fail fast
// instead of pacing more requests into a throttled endpoint.
return "", gate.ReportLimit()
}
if detail.Code != 0 {
return "", fmt.Errorf("AI provider reported an error (code %d)", detail.Code)
}