OpenRouter: models list: prevent schema changes from breaking working models. Fixes #787

This commit is contained in:
Enrico Ros
2025-04-05 10:26:44 -07:00
parent e7686f60b1
commit 5e2b196c4d
2 changed files with 8 additions and 3 deletions
@@ -742,10 +742,14 @@ export function openRouterModelFamilySortFn(a: { id: string }, b: { id: string }
return aPrefixIndex !== -1 ? -1 : 1;
}
export function openRouterModelToModelDescription(wireModel: object): ModelDescriptionSchema {
export function openRouterModelToModelDescription(wireModel: object): ModelDescriptionSchema | null {
// parse the model
const model = wireOpenrouterModelsListOutputSchema.parse(wireModel);
const { data: model, error } = wireOpenrouterModelsListOutputSchema.safeParse(wireModel);
if (error) {
console.warn(`openrouterModelToModelDescription: Failed to parse model: ${error}`);
return null;
}
// parse pricing
const pricing: ModelDescriptionSchema['pricing'] = {
@@ -256,7 +256,8 @@ export const llmOpenAIRouter = createTRPCRouter({
case 'openrouter':
models = openAIModels
.sort(openRouterModelFamilySortFn)
.map(openRouterModelToModelDescription);
.map(openRouterModelToModelDescription)
.filter(desc => !!desc);
break;
}