Cogitator
Core

Model Registry

Dynamic model registry with pricing, capabilities, and multi-provider support.

Overview

The @cogitator-ai/models package provides a dynamic model registry that tracks pricing, context windows, and capabilities for LLM models across all major providers. It fetches data from LiteLLM and OpenRouter's public model list, and works offline from built-in models and copies of both bundled with the package.

import { initializeModels, getModel, getPrice, listModels } from '@cogitator-ai/models';

await initializeModels();

const model = getModel('gpt-6.1-sol');
console.log(model?.contextWindow); // 1050000
console.log(model?.capabilities?.supportsVision); // true

const price = getPrice('claude-sonnet-5-5');
console.log(`$${price?.input}/M input, $${price?.output}/M output`);

Model ids are matched case-insensitively and aliases resolve too (claude-sonnet-5.5 → claude-sonnet-5-5). Lookups return null for unknown models.

Provider-qualified ids

The same model is often sold by several providers at different prices, so the registry keeps one entry per provider. Each entry's id is the model's name at that provider, provider is the registry's provider id, and catalogId is the key its catalogue lists it under (openrouter/<id> for a model of OpenRouter's list):

await initializeModels();

getModel('openrouter/deepseek/deepseek-v4-pro');
// { id: 'deepseek/deepseek-v4-pro', provider: 'openrouter',
//   catalogId: 'openrouter/deepseek/deepseek-v4-pro',
//   pricing: { input: 0.888966, output: 1.777932, inputCached: 0.0740805 }, ... }

getModel('azure_ai/deepseek-v4-pro')?.provider; // 'azure', at Azure's price
getModel('google/gemini-3.8-flash')?.id; // 'gemini-3.8-flash' (also found as gemini/gemini-3.8-flash)

A lookup resolves in this order:

  1. A provider-qualified id finds that provider's entry. Both Cogitator model strings (openai/gpt-6.1-sol, google/gemini-3.8-flash, openrouter/deepseek/deepseek-v4-pro) and LiteLLM keys (gemini/..., azure_ai/...) work. openrouter/* models are priced from OpenRouter's own model list, as OpenRouter bills them, not at the vendor's direct price, and OpenRouter's vendor names z-ai and x-ai are read as the providers zai and xai.
  2. When that provider does not list the model, the prefix is dropped and the rest is looked up, so openai/deepseek/deepseek-v4-pro (an OpenAI-compatible server) is priced as deepseek/deepseek-v4-pro.
  3. A bare name (deepseek-v4-pro) picks one listing by fixed rules, never by catalogue order: active models before deprecated ones, the vendor's own listing (a built-in model or an unprefixed LiteLLM key) before resellers, then the providers in BUILTIN_PROVIDERS order, then the shorter id, then alphabetically.

Pass the full model string your agent runs on to get that provider's price. The offline catalogue follows the same rules before initializeModels() runs.

Pricing and Cost

Prices are USD per million tokens. getPrice() returns only input and output; getPricing() returns the full ModelPricing, including prompt-cache prices:

import { getPricing, calculateCost } from '@cogitator-ai/models';

getPricing('claude-sonnet-5-5');
// { input: 2, output: 10, inputCached: 0.2, inputCacheWrite: 2.5, inputCacheWrite1h: 4 }

const cost = calculateCost('claude-sonnet-5-5', {
  inputTokens: 10_000,
  outputTokens: 1_000,
  cachedInputTokens: 8_000, // part of inputTokens read from the cache
  cacheWriteTokens: 0, // part of inputTokens written to the cache
});
// 0.0156 (USD), or null when the model's price is unknown

Cache reads and writes are charged at inputCached / inputCacheWrite where the model has them, and at the input price otherwise. Writes made with Anthropic's 1-hour TTL (cacheWrite1hTokens, a part of cacheWriteTokens) are charged at inputCacheWrite1h, twice the input price, instead of the 5-minute write price. RunResult.usage.cost adds up the cost of each model call. When the provider reports what a call cost (OpenRouter does, in usage.cost), the runtime takes that price, which also reflects which upstream served the call. Other calls are priced by llm.pricing first, then from the shared registry, using the full model string the agent runs on, so a model neither knows and whose provider reports nothing costs 0, and the runtime warns once per such model (models on Ollama and vLLM are free and stay quiet). A catalogue model listed without a price carries priceUnknown: true and has no price for these lookups, so it warns too instead of counting as free. Lookups made before initializeModels() use the offline catalogue without counting as initialization, so initializeModels() at startup still loads the current one whenever it runs.

Offline Catalogue

Without the network the registry still knows the built-in models, every model of the LiteLLM catalogue copy bundled with the package (LITELLM_SNAPSHOT, MIT licensed like LiteLLM) and the priced text models of the bundled copy of OpenRouter's model list (OPENROUTER_SNAPSHOT), so DeepSeek, Mistral, Bedrock, OpenRouter and the rest are priced before initializeModels() and when both the fetch and the cache fail. The built-in models take their prices and limits from the copies, as they do from fetched data. LITELLM_SNAPSHOT.fetchedAt and OPENROUTER_SNAPSHOT.fetchedAt say how old they are, and pnpm --filter @cogitator-ai/models snapshot refreshes both in the repository.

import { getPricing, LITELLM_SNAPSHOT } from '@cogitator-ai/models';

getPricing('deepseek/deepseek-chat'); // priced offline from the bundled copy
LITELLM_SNAPSHOT.fetchedAt; // 'YYYY-MM-DD'

ModelPricer

ModelPricer prices model calls from prices of your own first and the registry second, the way the runtime does with llm.pricing. A key matches the full model string or its tail after any /, the longest match first, case-insensitively: openai/gpt-4o prices only that model at OpenAI, gpt-4o prices it at every provider that serves it under that name.

import { ModelPricer, costOf, getPricing } from '@cogitator-ai/models';

const pricer = new ModelPricer({ 'my-finetune': { input: 0.3, output: 1.2 } });

pricer.pricing('openai/my-finetune'); // { input: 0.3, output: 1.2 }
pricer.cost('openai/my-finetune', { inputTokens: 10_000, outputTokens: 500 }); // 0.0036, null when unknown
pricer.hasOverride('gpt-4o'); // false, priced from the registry

costOf(getPricing('claude-sonnet-5-5')!, { inputTokens: 1000, outputTokens: 100 }); // USD at a given price

PricingOverrides is the type of the prices it takes, Record<string, ModelPricing>.

ModelRegistry

The ModelRegistry class manages model data with caching and auto-refresh.

import { ModelRegistry } from '@cogitator-ai/models';

const registry = new ModelRegistry({
  cache: {
    ttl: 24 * 60 * 60 * 1000,
    storage: 'file',
    filePath: './cache/models.json',
  },
  autoRefresh: true,
  refreshInterval: 24 * 60 * 60 * 1000,
  fallbackToBuiltin: true,
});

await registry.initialize();

Options

OptionDefaultDescription
cache.ttl24 hoursCache time-to-live in milliseconds
cache.storage'memory''memory' or 'file'
cache.filePath~/.cogitator/models-cache.jsonFile path for file-based cache (in memory where there is no file system, e.g. edge runtimes)
autoRefreshfalseAutomatically refresh data in background
refreshInterval24 hoursRefresh interval in milliseconds
fallbackToBuiltintrueUse the offline catalogue when fetch and cache fail

Methods

initialize() loads a fresh cache if there is one (and refreshes it in the background), otherwise fetches LiteLLM data and OpenRouter's model list, on failure it falls back to a stale cache, then to the offline catalogue (or throws when fallbackToBuiltin is false). When only OpenRouter cannot be fetched, its bundled copy takes its place, over LiteLLM as offline, with a warning, and the catalogue stays fresh in the cache for 15 minutes instead of the whole ttl, so the next load asks OpenRouter again. Lookups before initialize() use the offline catalogue without counting as initialization, so a later initialize() still loads the full catalogue. Overlapping initialize() calls share one load.

registry.getModel('gpt-6.1-sol');
registry.getPrice('gpt-6.1-sol');
registry.getPricing('gpt-6.1-sol');
registry.listModels({ provider: 'openai', supportsTools: true });
registry.listProviders();
registry.getProvider('anthropic');
registry.getModelCount();
registry.isInitialized();
await registry.refresh();
registry.shutdown();

Filtering

Use ModelFilter to query models by provider, capabilities, and cost:

import { listModels } from '@cogitator-ai/models';

const visionModels = listModels({ supportsVision: true, excludeDeprecated: true });

const cheapToolModels = listModels({
  supportsTools: true,
  maxPricePerMillion: 1.0,
});

const largeContext = listModels({
  minContextWindow: 200_000,
  provider: 'anthropic',
});

Filter Options

FilterTypeDescription
providerstringFilter by provider ID
supportsToolsbooleanFilter by tool/function calling support
supportsVisionbooleanFilter by vision/image support
minContextWindownumberMinimum context window size
maxPricePerMillionnumberMax average price per million tokens
excludeDeprecatedbooleanExclude deprecated models

Built-in Providers

The registry includes provider entries (BUILTIN_PROVIDERS) for 16 providers:

OpenAI (openai), Anthropic (anthropic), Google (google), Ollama (ollama), Azure OpenAI (azure), AWS Bedrock (aws), Mistral AI (mistral), Cohere (cohere), Groq (groq), Together AI (together), Fireworks AI (fireworks), DeepInfra (deepinfra), Perplexity (perplexity), Replicate (replicate), xAI (xai), OpenRouter (openrouter).

Built-in model data covers OpenAI, Anthropic, Google and the decision models of OpenRouter. Models of the other providers, and additional providers, come from LiteLLM data and, for openrouter, from OpenRouter's model list, the bundled copies until the catalogues are fetched. getProvider(id).models lists the model ids loaded for a provider.

Built-in Models

Built-in fallbacks cover current model families for major providers, including OpenAI GPT-6 (gpt-6-astra, gpt-6.1-sol, gpt-6-luna) and GPT-5.6/5.5, Anthropic Claude Opus 5.5 / Sonnet 5.5 / Fable 5.1 / Haiku 4.5, and Google Gemini 3.8 Flash / Gemini 3.5 Flash-Lite / Gemini 3.1 Pro Preview.

Retired or retiring models stay in the registry with deprecated: true so lookups and pricing keep working for existing configs — among them o3, o3-mini, o3-pro, o4-mini, gpt-4.1-nano, gpt-5.4-nano, gpt-4, gpt-4-turbo, claude-sonnet-4, claude-opus-4, claude-opus-4-1, the Claude 3.x models, and Gemini 2.5 / 2.0 / 1.5. Use excludeDeprecated: true (or filter on model.deprecated) to skip them.

import {
  BUILTIN_MODELS,
  OPENAI_MODELS,
  ANTHROPIC_MODELS,
  GOOGLE_MODELS,
} from '@cogitator-ai/models';

const activeOpenAI = OPENAI_MODELS.filter((model) => !model.deprecated);
const cheapToolModels = BUILTIN_MODELS.filter(
  (model) =>
    model.capabilities?.supportsTools && (model.pricing.input + model.pricing.output) / 2 <= 5
);

Decision Models

kind says what a model does: chat (when unset) answers messages, decision answers typed questions through cog.decide() and cannot chat. OPENROUTER_MODELS has TypeSafe's Jev (openrouter/typesafe/jev-1.13, also ~typesafe/jev-latest) at $0.042 per million input tokens with free output and a 32 000 token context. isDecisionModel(id) tells them apart, which the runtime uses to refuse a chat run on one.

import { isDecisionModel } from '@cogitator-ai/models';

isDecisionModel('openrouter/typesafe/jev-1.13'); // true
isDecisionModel('openai/gpt-6-luna'); // false

Caching

Models data is cached to avoid repeated network requests:

// Memory cache (default)
new ModelRegistry({ cache: { ttl: 3600000, storage: 'memory' } });

// File cache (persists across restarts)
new ModelRegistry({
  cache: { ttl: 86400000, storage: 'file', filePath: './models-cache.json' },
});

The cache supports stale-while-revalidate: if a refresh fails, the registry falls back to stale cached data before using the offline catalogue. Fetched data is merged over the built-in entries, so built-in models keep their display names and aliases with fresh prices.

ModelCache is exported for direct use (get(), getStale(), set(models), clear()).

LiteLLM Integration

For advanced use cases, you can fetch and transform LiteLLM data directly:

import { fetchLiteLLMData, transformLiteLLMData } from '@cogitator-ai/models';

const rawData = await fetchLiteLLMData();
const models = transformLiteLLMData(rawData);

OpenRouter Integration

OpenRouter's model list (GET https://openrouter.ai/api/v1/models, no API key) is fetched and transformed the same way:

import { fetchOpenRouterData, transformOpenRouterData } from '@cogitator-ai/models';

const entries = await fetchOpenRouterData();
const models = transformOpenRouterData(entries);

Each model gets provider openrouter and catalogId openrouter/<id>. Routers whose price depends on the model they pick (openrouter/auto) carry priceUnknown: true, models past their expiration_date are deprecated, and models that do not answer in text are left out. Time and prompt-size price overrides are not applied, the base price is used.

Zod Schemas

All types have corresponding Zod schemas for runtime validation:

import {
  ModelInfoSchema,
  ModelPricingSchema,
  ModelCapabilitiesSchema,
  ProviderInfoSchema,
} from '@cogitator-ai/models';

const result = ModelInfoSchema.safeParse(unknownData);
if (result.success) {
  console.log(result.data.id);
}

Global Functions

Convenience functions use a shared default registry:

import {
  initializeModels,
  getModel,
  getPrice,
  listModels,
  getModelRegistry,
  shutdownModels,
} from '@cogitator-ai/models';

await initializeModels();

getModel('gpt-6.1-sol');
getPrice('claude-sonnet-5-5');
listModels({ provider: 'google' });

shutdownModels();

These functions use the offline catalogue until the first initializeModels(), so it is optional but recommended for the latest data. The shared registry (getModelRegistry()) caches to the file ~/.cogitator/models-cache.json for 24 hours, and shutdownModels() stops it and discards it, so the next call creates a new one.

On this page