fixes #735: Reranking Models And /api/models
What happened
The upstream AI Gateway /config response included a model entry like:
{
"id": "cohere/rerank-v3.5",
"name": "Cohere Rerank 3.5",
"description": "Rerank 3.5 efficiently finds the most relevant business data to answer a user question...",
"modelType": "reranking",
"tags": [],
"specification": {
"specificationVersion": "v3",
"provider": "bedrock",
"modelId": "cohere/rerank-v3.5",
"type": "reranking"
},
"pricing": {
"input": "0",
"output": "0"
}
}Why it failed
The current SDK validation for gateway.getAvailableModels() only accepts these modelType values:
embeddingimagelanguagevideo
Because the Gateway payload included modelType: "reranking", the SDK rejected the entire response during validation.
That meant /api/models failed before our code could filter the response down to language models, so the route returned 500.
What this means for reranking models
Reranking models are not supported by this endpoint today.
They should not be returned by /api/models, because this route is used for language-model selection in the app. The correct behavior is:
- ignore unsupported non-language model types such as
reranking - continue returning valid language models
- avoid failing the whole endpoint because of unrelated model categories
Fix summary
We added a fallback path in apps/web/lib/models-with-context.ts so that when Gateway metadata validation fails, the app:
- inspects the raw error response
- extracts valid
languagemodel entries - ignores unsupported entries like reranking models
- continues serving
/api/modelssuccessfully
Result
After the fix:
- reranking models are skipped
- language models still load normally
/api/modelsreturns200instead of500
@8dazo is attempting to deploy a commit to the Vercel Labs Team on Vercel.
A member of the Team first needs to authorize it.