Skip to content

fix: tolerate unknown gateway model types in /api/models#736

Open
8dazo wants to merge 1 commit into
vercel-labs:mainfrom
8dazo:fix/api-models-gateway-fallback
Open

fix: tolerate unknown gateway model types in /api/models#736
8dazo wants to merge 1 commit into
vercel-labs:mainfrom
8dazo:fix/api-models-gateway-fallback

Conversation

@8dazo

@8dazo 8dazo commented Apr 14, 2026

Copy link
Copy Markdown

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:

  • embedding
  • image
  • language
  • video

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 language model entries
  • ignores unsupported entries like reranking models
  • continues serving /api/models successfully

Result

After the fix:

  • reranking models are skipped
  • language models still load normally
  • /api/models returns 200 instead of 500

@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown

@8dazo is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@8dazo

8dazo commented Apr 14, 2026

Copy link
Copy Markdown
Author

@willsather @nicoalbanese could please verify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: /api/models returns 500 when AI Gateway includes a new unsupported modelType

1 participant