From c08c0f2bc22fb5b27e2ccf51f08aa61fa3fd23ae Mon Sep 17 00:00:00 2001 From: Resham Joshi <65915470+iamtoruk@users.noreply.github.com> Date: Fri, 6 Nov 2026 05:53:42 -0800 Subject: [PATCH] fix(vercel-gateway): treat 408, 409 and 425 as retryable report failures A request timeout, conflict or too-early answer was read as a definitive empty report. They now keep the cached report and retry like 429 and 5xx: the statuses Vercel's own AI SDK retries, plus 425, which asks for a retry. --- src/providers/vercel-gateway.ts | 9 ++++++--- tests/providers/vercel-gateway.test.ts | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/providers/vercel-gateway.ts b/src/providers/vercel-gateway.ts index 98b20587..2a5bffae 100644 --- a/src/providers/vercel-gateway.ts +++ b/src/providers/vercel-gateway.ts @@ -11,6 +11,7 @@ import { fetchWithTimeout } from '../fetch-utils.js' // headline totals unless `includeGatewayInTotals` is set — see // `excludeProviderFromDay` in src/usage-aggregator.ts. const REPORT_URL = 'https://ai-gateway.vercel.sh/v1/report' +const RETRYABLE_STATUSES: ReadonlySet = new Set([408, 409, 425, 429]) type ReportRow = { day?: string @@ -65,9 +66,11 @@ export async function fetchVercelGatewayReport( 'Requires AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN (Pro/Enterprise for /v1/report). ' + `${detail.slice(0, 200)}\n`, ) - // A rate limit or server error says nothing about the spend: keep the - // cached report and retry. Other statuses (no access) mean no report. - if (res.status === 429 || res.status >= 500) throw new RetryableSourceError(`Vercel AI Gateway report HTTP ${res.status}`) + // A timeout, conflict, rate limit or server error says nothing about the + // spend: keep the cached report and retry. 408/409/429/5xx are the + // statuses Vercel's own AI SDK retries; 425 asks for a retry by + // definition. Other statuses (no access) mean no report. + if (RETRYABLE_STATUSES.has(res.status) || res.status >= 500) throw new RetryableSourceError(`Vercel AI Gateway report HTTP ${res.status}`) return [] } diff --git a/tests/providers/vercel-gateway.test.ts b/tests/providers/vercel-gateway.test.ts index ffc67ff4..0718d9a4 100644 --- a/tests/providers/vercel-gateway.test.ts +++ b/tests/providers/vercel-gateway.test.ts @@ -150,6 +150,7 @@ describe('vercel-gateway end-to-end (parseAllSessions network path)', () => { vi.spyOn(process.stderr, 'write').mockImplementation(() => true) for (const failing of [ vi.fn(async () => ({ ok: false, status: 503, text: async () => '' })), + vi.fn(async () => ({ ok: false, status: 408, text: async () => '' })), vi.fn(async () => { throw new Error('getaddrinfo ENOTFOUND') }), ]) { globalThis.fetch = failing as unknown as typeof fetch