For centralized requests, markKeyOnError extracts an Anthropic SDK error from err and marks the key based on its status code. Returns true if the status was a key-specific failover trigger so callers can retry with the next key.
(ctx context.Context, key *keypool.Key, err error)
| 577 | // its status code. Returns true if the status was a key-specific |
| 578 | // failover trigger so callers can retry with the next key. |
| 579 | func (i *interceptionBase) markKeyOnError(ctx context.Context, key *keypool.Key, err error) bool { |
| 580 | if i.cfg.KeyPool == nil { |
| 581 | return false |
| 582 | } |
| 583 | var apiErr *anthropic.Error |
| 584 | if !errors.As(err, &apiErr) { |
| 585 | return false |
| 586 | } |
| 587 | return keypool.MarkKeyOnStatus( |
| 588 | ctx, key, apiErr.Response, |
| 589 | i.logger, i.providerName, |
| 590 | ) |
| 591 | } |
| 592 | |
| 593 | // ResponseErrorFromKeyPool translates a *keypool.Error into |
| 594 | // a developer-facing ResponseError shaped for the Anthropic API. |