From c1d9b939f8e8979212562f03a9a0dc610195e16f Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 11 Mar 2026 11:08:04 +0100 Subject: [PATCH 1/3] url parameter to filter by provider --- packages/function/src/worker.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/function/src/worker.ts b/packages/function/src/worker.ts index beb8477b7..01473ca1a 100644 --- a/packages/function/src/worker.ts +++ b/packages/function/src/worker.ts @@ -75,6 +75,37 @@ export default { if (url.pathname === "/api.json") { url.pathname = "/_api.json"; + const providerParam = url.searchParams.get("provider"); + + if (providerParam) { + const apiResponse = await env.ASSETS.fetch( + new Request(url.toString(), request), + ); + const providers = (await apiResponse.json()) as Record< + string, + { models: Record } + >; + + if (providers[providerParam]) { + return new Response( + JSON.stringify(providers[providerParam].models), + { + headers: { + "Content-Type": "application/json", + "Cache-Control": "public, max-age=3600", + }, + }, + ); + } + + return new Response( + JSON.stringify({ error: `Provider '${providerParam}' not found` }), + { + status: 404, + headers: { "Content-Type": "application/json" }, + }, + ); + } } else if ( url.pathname === "/" || url.pathname === "/index.html" || From d6da3428eaab37f7a76cb6f2af6a9cec3f9ba93e Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 11 Mar 2026 11:12:58 +0100 Subject: [PATCH 2/3] flatten the output --- packages/function/src/worker.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/function/src/worker.ts b/packages/function/src/worker.ts index 01473ca1a..9e75c5962 100644 --- a/packages/function/src/worker.ts +++ b/packages/function/src/worker.ts @@ -76,6 +76,7 @@ export default { if (url.pathname === "/api.json") { url.pathname = "/_api.json"; const providerParam = url.searchParams.get("provider"); + const flattenParam = url.searchParams.get("flatten"); if (providerParam) { const apiResponse = await env.ASSETS.fetch( @@ -87,15 +88,26 @@ export default { >; if (providers[providerParam]) { - return new Response( - JSON.stringify(providers[providerParam].models), - { + const models = providers[providerParam].models; + + if (flattenParam === "true") { + const flattened = Object.entries(models).map( + ([id, model]) => ({ id, ...model as object }), + ); + return new Response(JSON.stringify(flattened), { headers: { "Content-Type": "application/json", "Cache-Control": "public, max-age=3600", }, + }); + } + + return new Response(JSON.stringify(models), { + headers: { + "Content-Type": "application/json", + "Cache-Control": "public, max-age=3600", }, - ); + }); } return new Response( From 32a8c49721126320dd823a267e8ed88556d77cc2 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 11 Mar 2026 11:13:41 +0100 Subject: [PATCH 3/3] update readme --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 410385a16..b2ea40280 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,33 @@ You can access this data through an API. curl https://models.dev/api.json ``` +### Query Parameters + +| Parameter | Description | Default | +|-----------|-------------|---------| +| `provider` | Filter to a specific provider's models only | All providers | +| `flatten` | Return models as a flat array with `id` field included | `false` | + +### Examples + +Get all providers and models: + +```bash +curl https://models.dev/api.json +``` + +Get models for a specific provider: + +```bash +curl "https://models.dev/api.json?provider=anthropic" +``` + +Get models for a specific provider as a flat array: + +```bash +curl "https://models.dev/api.json?provider=anthropic&flatten=true" +``` + Use the **Model ID** field to do a lookup on any model; it's the identifier used by [AI SDK](https://ai-sdk.dev/). ### Logos