fix(pricing): guard malformed models.dev model entries (#1344)

* fix(pricing): guard malformed models.dev model entries

* style: apply prettier formatting
This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-05-23 16:55:05 -04:00
1 parent af7aa0c2dd
commit 66966f3527
2 files changed
+22

No files matched your search

@@ -91,6 +91,7 @@ function findModel(provider: ModelsDevProvider, model: string): ModelsDevModel |
const normalizedEntries = new Map<string, ModelsDevModel>();
for (const [key, value] of Object.entries(models)) {
if (!value || typeof value !== 'object') continue;
normalizedEntries.set(normalizeId(key), value);
if (typeof value.id === 'string') normalizedEntries.set(normalizeId(value.id), value);
}
@@ -188,6 +189,7 @@ export function getKnownModelsDevModels(): string[] {
const ids = new Set<string>();
for (const provider of Object.values(registry)) {
for (const model of Object.values(provider.models ?? {})) {
if (!model || typeof model !== 'object') continue;
if (typeof model.id === 'string') ids.add(`${provider.id}/${model.id}`);
}
}