* Check if an error is a rate limit (throttling) or quota exhaustion error. * Some providers (e.g. Perplexity) return 401/403 with "insufficient_quota" * instead of the standard 429, so we also inspect the error message.
(error: unknown)
| 367 | * instead of the standard 429, so we also inspect the error message. |
| 368 | */ |
| 369 | function isRateLimitError(error: unknown): boolean { |
| 370 | if (error && typeof error === 'object') { |
| 371 | const status = (error as { status?: number }).status |
| 372 | if (status === 429 || status === 503) return true |
| 373 | |
| 374 | if (status === 401 || status === 403) { |
| 375 | const message = ((error as { message?: string }).message || '').toLowerCase() |
| 376 | if (message.includes('quota') || message.includes('rate limit')) { |
| 377 | return true |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | return false |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Map a thrown tool error to a hosted-key failure reason for metrics. Mirrors |