Repository navigation
feat(ai-models): build the catalog from modelschemas, not models.dev #1791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tombeckenham
wants to merge
7
commits into
main
Choose a base branch
from
1788-move-to-modelschemas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+48,231
−2
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a352ced
feat(ai-models): a runtime catalog of models, prices, and capabilities
AlemTuzlak b5450a6
Merge remote-tracking branch 'origin/feat/ai-models-catalog' into 178…
tombeckenham 258ff88
feat(ai-models): generate the catalog from modelschemas, not models.dev
tombeckenham 00bbee5
chore(ai-models): fetch modelschemas in one call, refresh the snapshot
tombeckenham 50f168d
test(ai-models): narrow reasoning before reading levels
tombeckenham 465295b
Merge commit 'fa2a291f5526f6dec9a91fe5b71de15dfaf59ec7' into HEAD
AlemTuzlak a2675bb
Merge remote-tracking branch 'origin/main' into HEAD
AlemTuzlak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@tanstack/ai-models': minor | ||
| --- | ||
|
|
||
| New package: a runtime catalog of more than 1,900 models across 38 providers, generated from modelschemas. `getProviders`, `getModels`, and `getModel` return each model's id, input modalities, context window, output limit, prices, reasoning data, and request quirks (`compat`). A record's `reasoning` has the `ModelReasoning` shape of `@tanstack/ai` (`false`, or `{ levels, budget }`). `supportedReasoningLevels`, `clampReasoningLevel`, and `modelCost` work on a record, and `generatedAt` is the date of the data. Each provider also has its own subpath, for example `@tanstack/ai-models/deepseek`. | ||
|
|
||
| `modelCost` prices long context and 1-hour cache writes. A record's `cost.tiers` holds higher prices above an input size, and a call uses the tier with the highest `inputTokensAbove` below its input. `TokenCounts.cacheWrite1h`, the part of `cacheWrite` with a 1-hour retention, costs 2 times the input price. | ||
|
|
||
| The `google-vertex` and `azure-openai-responses` providers have only the models on their own wire, so no Claude models. Use `anthropicVertexText` from `@tanstack/ai-anthropic/vertex` for Claude on Vertex. Embedding, reranking, and transcription models are not in the catalog. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| --- | ||
| title: Model Catalog | ||
| id: catalog | ||
| description: "Look up models, reasoning levels, prices, and context windows at runtime with @tanstack/ai-models." | ||
| keywords: | ||
| - tanstack ai | ||
| - model catalog | ||
| - modelschemas | ||
| - model metadata | ||
| - reasoning levels | ||
| - model pricing | ||
| --- | ||
|
|
||
| A model picker, a cost display, or a settings menu needs facts about models at runtime: which models a provider has, which reasoning levels a model takes, and what a call costs. `@tanstack/ai-models` is a catalog of that data for more than 1,900 models across 38 providers. | ||
|
|
||
| ## Install | ||
|
|
||
| <!-- ::start:tabs variant="package-manager" mode="install" --> | ||
|
|
||
| react: @tanstack/ai-models | ||
| vue: @tanstack/ai-models | ||
| solid: @tanstack/ai-models | ||
| svelte: @tanstack/ai-models | ||
| preact: @tanstack/ai-models | ||
| angular: @tanstack/ai-models | ||
| vanilla: @tanstack/ai-models | ||
| octane: @tanstack/ai-models | ||
|
|
||
| <!-- ::end:tabs --> | ||
|
|
||
| ## Look up a model | ||
|
|
||
| ```typescript | ||
| import { getModel, getModels, getProviders } from "@tanstack/ai-models"; | ||
|
|
||
| const providers = getProviders(); // every provider: id, name, baseUrl, env | ||
| const deepseekModels = getModels("deepseek"); // every DeepSeek model | ||
| const model = getModel("deepseek", "deepseek-v4-flash"); | ||
|
|
||
| console.log(model?.contextWindow, model?.maxTokens, model?.input); | ||
| ``` | ||
|
|
||
| Each record has the model's `id`, `name`, `input` modalities, `contextWindow`, `maxTokens`, prices, and reasoning data. `getModel` returns `undefined` for a model the catalog does not have. | ||
|
|
||
| The `google-vertex` provider has the Gemini models only. For Claude on Vertex, use `anthropicVertexText` from `@tanstack/ai-anthropic/vertex`. | ||
|
|
||
| ## Show the reasoning levels | ||
|
|
||
| `supportedReasoningLevels` gives the levels a model takes. Use it to fill a menu: | ||
|
|
||
| ```typescript | ||
| import { getModel, supportedReasoningLevels } from "@tanstack/ai-models"; | ||
|
|
||
| const model = getModel("deepseek", "deepseek-v4-flash"); | ||
| const levels = model ? supportedReasoningLevels(model) : []; | ||
| // ["off", "low", "high", "max"] | ||
| ``` | ||
|
|
||
| `clampReasoningLevel(model, level)` gives the nearest level the model has, for a level it does not have. Pass the level to [`chat({ reasoning })`](../chat/reasoning). | ||
|
|
||
| A record's `reasoning` is `false` for a model that does not reason. Otherwise it has two fields: | ||
|
|
||
| - `levels`: the provider value to send for each level the model has. | ||
| - `budget`: `true` when the model takes a thinking token budget. | ||
|
|
||
| This is the same shape as `ModelReasoning` in `@tanstack/ai`. | ||
|
|
||
| ## Work out what a call cost | ||
|
|
||
| Prices are per million tokens, in USD. A record with `cost.currency` (for example `"CNY"`) is priced in that currency instead. `modelCost` turns token counts into a cost, in the same currency. `input` is the uncached input: | ||
|
|
||
| ```typescript | ||
| import { getModel, modelCost } from "@tanstack/ai-models"; | ||
|
|
||
| const model = getModel("openai", "gpt-5.6"); | ||
| if (model) { | ||
| const cost = modelCost(model, { input: 12_000, output: 800 }); | ||
| console.log(cost.total.toFixed(4)); | ||
| } | ||
| ``` | ||
|
|
||
| `modelCost` also uses two price rules: | ||
|
|
||
| - **Long context.** Some models cost more above an input size. The record lists these prices in `cost.tiers`. A call uses the tier with the highest `inputTokensAbove` below its input (uncached, plus cache reads, plus cache writes). | ||
| - **1-hour cache writes.** `cacheWrite1h` is the part of `cacheWrite` that has a 1-hour retention. It costs 2 times the input price. | ||
|
|
||
| To price each call of a chat, read its usage in middleware: | ||
|
|
||
| ```typescript | ||
| import type { ChatMiddleware } from "@tanstack/ai"; | ||
| import { getModel, modelCost } from "@tanstack/ai-models"; | ||
|
|
||
| const model = getModel("anthropic", "claude-sonnet-5-5"); | ||
|
|
||
| const logCost: ChatMiddleware = { | ||
| name: "log-cost", | ||
| onUsage(_ctx, usage) { | ||
| if (!model) return; | ||
| const details = usage.promptTokensDetails; | ||
| const cacheRead = details?.cachedTokens ?? 0; | ||
| const cacheWrite = details?.cacheWriteTokens ?? 0; | ||
| const cost = modelCost(model, { | ||
| input: usage.promptTokens - cacheRead - cacheWrite, | ||
| output: usage.completionTokens, | ||
| cacheRead, | ||
| cacheWrite, | ||
| }); | ||
| console.log(cost.total.toFixed(4)); | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| ## Load one provider only | ||
|
|
||
| The root import has every provider. To load only one, import its subpath: | ||
|
|
||
| ```typescript | ||
| import { models, provider } from "@tanstack/ai-models/deepseek"; | ||
|
|
||
| console.log(provider.baseUrl, models.length); | ||
| ``` | ||
|
|
||
| ## Keep it up to date | ||
|
|
||
| The catalog comes from [modelschemas](https://modelschemas.com), which reads each provider's own model list, docs, and price page. `generatedAt` is the date of the last update. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2025 Tanner Linsley | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <div align="center"> | ||
| <picture> | ||
| <source | ||
| media="(prefers-color-scheme: dark)" | ||
| srcset="https://tanstack.com/api/readme/ai.png?theme=dark" | ||
| /> | ||
| <source | ||
| media="(prefers-color-scheme: light)" | ||
| srcset="https://tanstack.com/api/readme/ai.png" | ||
| /> | ||
| <img | ||
| src="https://tanstack.com/api/readme/ai.png" | ||
| alt="TanStack AI" | ||
| width="900" | ||
| /> | ||
| </picture> | ||
| </div> | ||
|
|
||
| <br /> | ||
|
|
||
| # @tanstack/ai-models | ||
|
|
||
| A model catalog you can read at runtime: each model's context window, price, reasoning levels, input kinds, and wire quirks, for more than 1,900 models across 38 providers. | ||
|
|
||
| ```ts | ||
| import { getModel, modelCost, clampReasoningLevel } from '@tanstack/ai-models' | ||
|
|
||
| const model = getModel('deepseek', 'deepseek-v4-flash') | ||
| if (model) { | ||
| model.contextWindow // 1000000 | ||
| modelCost(model, { input: 12_000, output: 800 }).total // USD, unless model.cost.currency says otherwise | ||
| clampReasoningLevel(model, 'medium') // 'high': the nearest level the model has | ||
| } | ||
| ``` | ||
|
|
||
| - No dependencies, and no Node.js APIs, so it runs on edge runtimes too. | ||
| - One subpath per provider (`@tanstack/ai-models/deepseek`), so a build ships only the providers it imports. | ||
| - The data comes from [modelschemas](https://modelschemas.com). `pnpm generate:models` refreshes it. | ||
|
|
||
| Read the guide: [Model catalog](https://tanstack.com/ai/latest/docs/models/catalog). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
The docs examples use model ids that the generated catalog does not have. The examples call
getModelwithdeepseek-v4-flashandgpt-5.6. Neither id is in the catalog, sogetModelreturnsundefined. Theif (model)guards hide the failure, so the examples print nothing. The comments that show the results are also wrong.docs/models/catalog.md#L38-L38: UsegetModel("deepseek", "deepseek-flash").docs/models/catalog.md#L54-L56: Usedeepseek-flash. Change the comment to["low", "high", "max"], because this model has noofflevel.docs/models/catalog.md#L75-L75: Use an id that exists, for examplegetModel("openai", "gpt-5.6-sol").packages/ai-models/README.md#L28-L32: UsegetModel('deepseek', 'deepseek-flash'). Change thecontextWindowcomment to// 1048576.📍 Affects 2 files
docs/models/catalog.md#L38-L38(this comment)docs/models/catalog.md#L54-L56docs/models/catalog.md#L75-L75packages/ai-models/README.md#L28-L32🤖 Prompt for AI Agents