Fix Vercel AI Gateway model fetching (#9791)

Co-authored-by: Roo Code <roomote@roocode.com>
This commit is contained in:
Chris Estreich 2025-12-03 11:46:15 -08:00 committed by GitHub
parent 86edc01cb1
commit 1879200964
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 13 deletions

View file

@ -108,10 +108,7 @@ describe("Vercel AI Gateway Fetchers", () => {
const models = await getVercelAiGatewayModels()
expect(models).toEqual({})
expect(consoleErrorSpy).toHaveBeenCalledWith(
"Vercel AI Gateway models response is invalid",
expect.any(Object),
)
expect(consoleErrorSpy).toHaveBeenCalled()
consoleErrorSpy.mockRestore()
})

View file

@ -12,10 +12,11 @@ import { parseApiPrice } from "../../../shared/cost"
*/
const vercelAiGatewayPricingSchema = z.object({
input: z.string(),
output: z.string(),
input: z.string().optional(), // Image models don't have an input price.
output: z.string().optional(), // Embedding and image models don't have an output price.
input_cache_write: z.string().optional(),
input_cache_read: z.string().optional(),
image: z.string().optional(), // Only image models have an image price.
})
/**
@ -62,22 +63,19 @@ export async function getVercelAiGatewayModels(options?: ApiHandlerOptions): Pro
const data = result.success ? result.data.data : response.data.data
if (!result.success) {
console.error("Vercel AI Gateway models response is invalid", result.error.format())
console.error(`Vercel AI Gateway models response is invalid ${JSON.stringify(result.error.format())}`)
}
for (const model of data) {
const { id } = model
// Only include language models for chat inference
// Embedding models are statically defined in embeddingModels.ts
// Only include language models for chat inference.
// Embedding models are statically defined in embeddingModels.ts.
if (model.type !== "language") {
continue
}
models[id] = parseVercelAiGatewayModel({
id,
model,
})
models[id] = parseVercelAiGatewayModel({ id, model })
}
} catch (error) {
console.error(