openclaw-grafana-lens
Version:
OpenClaw plugin that gives AI agents full Grafana access — 18 composable tools for PromQL/LogQL/TraceQL queries, dashboard creation, alerting, SRE investigation, security monitoring, data collection pipeline management via Grafana Alloy (29 recipes), and
48 lines (47 loc) • 1.89 kB
TypeScript
/**
* Fallback model pricing for cost estimation.
*
* When openclaw's `estimateUsageCost()` returns undefined (because the user
* hasn't configured model pricing in openclaw.json), this module provides
* well-known pricing for popular models so cost dashboard panels still work.
*
* Pricing: USD per 1M tokens — matches openclaw's ModelCostConfig shape.
* Returns undefined for unknown models (no guessing).
*/
type ModelCost = {
input: number;
output: number;
cacheRead: number;
cacheWrite: number;
};
type TokenUsage = {
input?: number;
output?: number;
cacheRead?: number;
cacheWrite?: number;
};
/**
* Estimate cost when openclaw's pricing config is missing.
* Formula matches openclaw's estimateUsageCost():
* (input × inputCost + output × outputCost + cacheRead × cacheReadCost + cacheWrite × cacheWriteCost) / 1_000_000
*
* Returns undefined for unknown provider/model combos.
*/
/**
* Resolve model pricing from openclaw's config — the same config that
* openclaw's own `resolveModelCostConfig()` reads. This covers ALL
* user-configured models, not just the 6 hardcoded Anthropic ones.
*
* Config path: `config.models.providers[provider].models[{id: model}].cost`
*
* Returns undefined if the provider/model isn't configured or has no cost entry.
*/
export declare function resolveModelCostFromConfig(config: Record<string, unknown>, provider?: string, model?: string): ModelCost | undefined;
/**
* Estimate cost from a resolved ModelCost and token usage.
* Same formula as openclaw's estimateUsageCost():
* (input × inputCost + output × outputCost + ...) / 1_000_000
*/
export declare function estimateUsageCost(pricing: ModelCost, usage?: TokenUsage): number | undefined;
export declare function estimateCostFallback(provider?: string, model?: string, usage?: TokenUsage): number | undefined;
export {};