The OpenAI client is created with the SDK defaults, which silently retry 408, 409, 429 and every 5xx twice before callLlm sees the error. report.ts:191-196 says a 5xx must not be retried because it risks a duplicate generation that was already billed, so the SDK does exactly what the app's policy rules out, and callLlm's own 429 and connection ladders run on top of it (up to 3 x 7 = 21 HTTP attempts per call).
- What to change
- Pass maxRetries: 0 to new OpenAI(...) in openai-compatible.ts (and to new Anthropic() in anthropic.ts), so callLlm's ladder is the only retry layer.
- Why it matters
- Each SDK retry of a 5xx resends the full prompt and, if the provider had started generating, pays for the output again.
- How often it happens
- The code shows the problem; how often it happens is assumed. To measure it: How often DashScope returns a 5xx or 408/409 on this endpoint, from the Actions logs or the Model Studio console; a 5xx retried by the SDK leaves no line in the app's log.
- Estimate
- about 23k tokens per 1,000 calls if 2 in 1,000 calls hit a billed 5xx (estimate)
What the estimate assumes
2 of 1,000 calls get a 5xx after generation started; a digest call is about 7,000 prompt and 2,200 output tokens; each SDK retry repeats both. Connection failures, the common case here, cost no tokens and are not counted.