In-memory cache for gateway model pricing keyed by provider and model, with normalization for wrapper providers. Reuse for pricing lookups and cost estimation.
// Source: https://github.com/linuxhsj/openclaw-zero-token | License: MIT | Copyright 2025 Peter Steinberger
// Provided via justclaw.it.com; keep this notice with the code.
import { normalizeModelRef } from "../agents/model-selection.js";
import { normalizeProviderId } from "../agents/provider-id.js";
export type CachedModelPricing = {
input: number;
output: number;
cacheRead: number;
cacheWrite: number;
};
let cachedPricing = new Map<string, CachedModelPricing>();
let cachedAt = 0;
const WRAPPER_PROVIDERS = new Set([
"cloudflare-ai-gateway",
"kilocode",
"openrouter",
"vercel-ai-gateway",
]);
function modelPricingCacheKey(provider: string, model: string): string {
const providerId = normalizeProviderId(provider);
const modelId = model.trim();
if (!providerId || !
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key