Skip to content
Merged
70 changes: 70 additions & 0 deletions apps/gateway/src/models/models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,74 @@ describe("Models API", () => {
"image",
]);
});

test("GET /v1/models should include stability information for models", async () => {
const res = await app.request("/v1/models");
expect(res.status).toBe(200);

const json = await res.json();

// Check that the stability field exists in the model schema (models may or may not have it set)
const modelsWithStability = json.data.filter(
(model: any) => model.stability !== undefined,
);
// At least one model should have stability information (our DeepSeek models)
expect(modelsWithStability.length).toBeGreaterThan(0);

// Find DeepSeek models to test specific stability flags
const deepSeekV3 = json.data.find(
(model: any) => model.id === "deepseek-v3",
);
const deepSeekR1 = json.data.find(
(model: any) => model.id === "deepseek-r1",
);
const deepSeekR1Distill = json.data.find(
(model: any) => model.id === "deepseek-r1-distill-llama-70b",
);
const deepSeekV31 = json.data.find(
(model: any) => model.id === "deepseek-v3.1",
);

if (deepSeekV3) {
expect(deepSeekV3.stability).toBe("unstable");
}

if (deepSeekR1) {
expect(deepSeekR1.stability).toBe("unstable");
}

if (deepSeekR1Distill) {
expect(deepSeekR1Distill.stability).toBe("beta");
}

// DeepSeek v3.1 should default to stable (undefined in response means stable)
if (deepSeekV31) {
expect(
deepSeekV31.stability === undefined ||
deepSeekV31.stability === "stable",
).toBe(true);
}
});

test("GET /v1/models should handle stability field values correctly", async () => {
const res = await app.request("/v1/models");
expect(res.status).toBe(200);

const json = await res.json();

// Validate that stability field contains only valid values
const validStabilityValues = [
"stable",
"beta",
"unstable",
"experimental",
undefined,
];

for (const model of json.data) {
if (model.stability !== undefined) {
expect(validStabilityValues).toContain(model.stability);
}
}
});
});
6 changes: 6 additions & 0 deletions apps/gateway/src/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const modelSchema = z.object({
tools: z.boolean(),
parallelToolCalls: z.boolean(),
reasoning: z.boolean(),
stability: z
.enum(["stable", "beta", "unstable", "experimental"])
.optional(),
}),
),
pricing: z.object({
Expand All @@ -62,6 +65,7 @@ const modelSchema = z.object({
free: z.boolean().optional(),
deprecated_at: z.string().optional(),
deactivated_at: z.string().optional(),
stability: z.enum(["stable", "beta", "unstable", "experimental"]).optional(),
});

const listModelsResponseSchema = z.object({
Expand Down Expand Up @@ -196,6 +200,7 @@ modelsApi.openapi(listModels, async (c) => {
tools: provider.tools || false,
parallelToolCalls: provider.parallelToolCalls || false,
reasoning: provider.reasoning || false,
stability: provider.stability || model.stability,
};
}),
pricing: {
Expand All @@ -220,6 +225,7 @@ modelsApi.openapi(listModels, async (c) => {
free: model.free || false,
deprecated_at: model.deprecatedAt?.toISOString(),
deactivated_at: model.deactivatedAt?.toISOString(),
stability: model.stability,
};
});

Expand Down
85 changes: 81 additions & 4 deletions apps/ui/src/app/models/[name]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
models as modelDefinitions,
providers as providerDefinitions,
type StabilityLevel,
type ModelDefinition,
} from "@llmgateway/models";
import { AlertTriangle } from "lucide-react";
import { notFound } from "next/navigation";

import Footer from "@/components/landing/footer";
import { Navbar } from "@/components/landing/navbar";
import { CopyModelName } from "@/components/models/copy-model-name";
import { ProviderCard } from "@/components/models/provider-card";
import { Badge } from "@/lib/components/badge";

interface PageProps {
params: Promise<{ name: string }>;
Expand All @@ -17,12 +21,43 @@ export default async function ModelPage({ params }: PageProps) {
const { name } = await params;
const decodedName = decodeURIComponent(name);

const modelDef = modelDefinitions.find((m) => m.id === decodedName);
const modelDef = modelDefinitions.find(
(m) => m.id === decodedName,
) as ModelDefinition;

Comment on lines +24 to 27

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid unsafe cast; let notFound() narrow the type

-const modelDef = modelDefinitions.find(
-  (m) => m.id === decodedName,
-) as ModelDefinition;
+const modelDef = modelDefinitions.find((m) => m.id === decodedName);

Type narrows after notFound().

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const modelDef = modelDefinitions.find(
(m) => m.id === decodedName,
) as ModelDefinition;
const modelDef = modelDefinitions.find((m) => m.id === decodedName);
🤖 Prompt for AI Agents
In apps/ui/src/app/models/[name]/page.tsx around lines 24 to 27, remove the
unsafe "as ModelDefinition" cast on modelDef and instead let TypeScript narrow
the type by checking for a falsy value and calling notFound() when modelDef is
undefined; i.e., assign modelDef directly from modelDefinitions.find(...), then
immediately if (!modelDef) notFound(), so subsequent code treats modelDef as a
ModelDefinition without an explicit cast.

if (!modelDef) {
notFound();
}

const getStabilityBadgeProps = (stability?: StabilityLevel) => {
switch (stability) {
case "beta":
return {
variant: "secondary" as const,
color: "text-blue-600",
label: "BETA",
};
case "unstable":
return {
variant: "destructive" as const,
color: "text-red-600",
label: "UNSTABLE",
};
case "experimental":
return {
variant: "destructive" as const,
color: "text-orange-600",
label: "EXPERIMENTAL",
};
default:
return null;
}
};

const shouldShowStabilityWarning = (stability?: StabilityLevel) => {
return stability && ["unstable", "experimental"].includes(stability);
};

const modelProviders = modelDef.providers.map((provider) => {
const providerInfo = providerDefinitions.find(
(p) => p.id === provider.providerId,
Expand All @@ -39,11 +74,33 @@ export default async function ModelPage({ params }: PageProps) {
<div className="min-h-screen bg-background py-32">
<div className="container mx-auto px-4 py-8">
<div className="mb-8">
<h1 className="text-4xl font-bold tracking-tight mb-2">
{modelDef.id}
</h1>
<div className="flex items-center gap-3 mb-2">
<h1 className="text-4xl font-bold tracking-tight">
{modelDef.id}
</h1>
{shouldShowStabilityWarning(modelDef.stability) && (
<AlertTriangle className="h-8 w-8 text-orange-500" />
)}
</div>
<div className="flex items-center gap-2 mb-4">
<CopyModelName modelName={decodedName} />
{(() => {
const stabilityProps = getStabilityBadgeProps(
modelDef.stability,
);
return stabilityProps ? (
<Badge
variant={stabilityProps.variant}
className="text-sm px-3 py-1"
>
{stabilityProps.label}
</Badge>
) : (
<Badge variant="outline" className="text-sm px-3 py-1">
STABLE
</Badge>
);
})()}
</div>
Comment on lines +87 to 104

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Apply badge color classes

-<Badge
-  variant={stabilityProps.variant}
-  className="text-sm px-3 py-1"
->
+<Badge
+  variant={stabilityProps.variant}
+  className={`text-sm px-3 py-1 ${stabilityProps.color ?? ""}`}
+>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{(() => {
const stabilityProps = getStabilityBadgeProps(
modelDef.stability,
);
return stabilityProps ? (
<Badge
variant={stabilityProps.variant}
className="text-sm px-3 py-1"
>
{stabilityProps.label}
</Badge>
) : (
<Badge variant="outline" className="text-sm px-3 py-1">
STABLE
</Badge>
);
})()}
</div>
{(() => {
const stabilityProps = getStabilityBadgeProps(
modelDef.stability,
);
return stabilityProps ? (
<Badge
variant={stabilityProps.variant}
className={`text-sm px-3 py-1 ${stabilityProps.color ?? ""}`}
>
{stabilityProps.label}
</Badge>
) : (
<Badge variant="outline" className="text-sm px-3 py-1">
STABLE
</Badge>
);
})()}
🤖 Prompt for AI Agents
In apps/ui/src/app/models/[name]/page.tsx around lines 87 to 104, the badge
currently always uses the same styling and doesn't apply the color classes
provided by the stability metadata; update the JSX so the Badge receives the
stability color classes by merging the existing "text-sm px-3 py-1" with the
stabilityProps.className (or stabilityProps.colorClass) when stabilityProps
exists, and when falling back to the default branch provide the appropriate
default color class(es) instead of only "outline" so the badge shows the
intended color; ensure you keep the variant prop and properly concatenate class
strings safely (e.g., conditional join) so absent fields don't break rendering.


<div className="flex flex-wrap gap-4 text-sm text-muted-foreground mb-4">
Expand Down Expand Up @@ -86,6 +143,26 @@ export default async function ModelPage({ params }: PageProps) {
different configurations, pricing, and performance
characteristics. Choose the provider that best fits your needs.
</p>
{shouldShowStabilityWarning(modelDef.stability) && (
<div className="mt-4 p-4 bg-orange-50 border border-orange-200 rounded-lg">
<div className="flex items-start gap-3">
<AlertTriangle className="h-5 w-5 text-orange-500 mt-0.5 flex-shrink-0" />
<div>
<h3 className="font-medium text-orange-800 mb-1">
{modelDef.stability === "experimental"
? "Experimental"
: "Unstable"}{" "}
Model Warning
</h3>
<p className="text-sm text-orange-700">
This model is marked as {modelDef.stability} and may have
issues with reliability, performance, or consistency. Use
with caution in production environments.
</p>
</div>
</div>
</div>
)}
</div>

<div className="mb-8">
Expand Down
Loading