DEV Community

Assili Salim
Assili Salim

Posted on

Why Unknown Model Pricing Should Fail Closed in AI-Agent Runtimes

The problem

Unknown model pricing looks like a small configuration issue.

For AI agents, it can become a runtime failure.

A basic LLM application might send one request and inspect the cost later.

An AI agent is different.

An agent can:

call a model
retry
call tools
add more context
switch models
continue for many steps
fail slowly without crashing

That means one pricing mistake can multiply across a run.

If the runtime does not know the model price, it cannot safely enforce a budget.

That is why unknown model pricing should fail closed before provider API calls execute.

What “fail closed” means

Failing closed means the system refuses to continue when it cannot make a safe decision.

In this case, the decision is:

Should this next provider call be allowed?

If the runtime knows the model price, it can estimate cost and compare it against the run budget.

If the runtime does not know the model price, it should stop.

Not warn only.

Not guess.

Not assume the model is cheap.

Stop and return a structured error.

Why this matters more for agents

Agents are loops.

That is the core issue.

A single model call with unknown pricing is one risk.

An agent loop with unknown pricing is repeated risk.

The agent might make 10, 20, or 50 calls before anyone notices.

The failure may come from something simple:

a typo in the model name
a provider alias that changed
a fallback model that is more expensive
a wrapper passing an unexpected model string
a development config that differs from production
a new model added without pricing metadata

None of these are dramatic.

But cost failures usually are not dramatic.

They are boring runtime mistakes that continue too long.

Budget guards need reliable inputs

A budget guard depends on pricing metadata.

Before a provider call, the runtime might try to answer:

What model is being used?
What is the estimated input cost?
What is the estimated output cost?
How much budget remains for this run?
Should this call be allowed?

If pricing is missing, the budget decision becomes weak.

Here is the rough idea in TypeScript-oriented terms:

const decision = guard.beforeCall({
runId,
model,
inputTokens,
maxOutputTokens,
budget,
});

if (!decision.allowed) {
throw decision.error;
}

const result = await provider.call({
model,
messages,
});

The important part is placement.

The guard runs before the provider call.

If the model price is unknown, execution stops before spend happens.

Why a dashboard is too late

Provider dashboards are useful.

Billing dashboards are useful.

Logs and traces are useful.

But they usually answer the question after execution:

What happened?

Runtime guards answer a different question:

Should this next call happen?

For AI agents, that second question is critical.

Once the provider call executes, the cost exists.

A dashboard might help you understand the mistake.

A pre-call runtime guard can prevent the mistake from continuing.

A safer default

A safe model-pricing rule can be simple:

if (!pricingCatalog.has(model)) {
throw new UnknownModelPricingError(model);
}

This is not complex.

That is the point.

The runtime should not need advanced reasoning to avoid obvious cost ambiguity.

If the price is unknown, the call should not proceed.

The developer can then add pricing metadata, correct the model name, or explicitly change the configuration.

That is better than silent guessing.

Where AI CostGuard fits

This is one of the checks I am building into AI CostGuard.

AI CostGuard is a local-first TypeScript / Node.js runtime safety layer for AI agents.

It is designed to catch cost and loop failures before provider API calls execute.

It focuses on:

retry storm detection
similar prompt loop detection
unknown model pricing blocks
max-step protection
budget guards
middleware and wrappers
structured errors

It is not a billing ledger.

It is not a hard security boundary.

It is not an enterprise firewall.

It is a pre-call runtime kill switch for AI-agent cost and loop failures.

The npm package is @salimassili/ai-costguard.

The takeaway

AI-agent cost control needs boring rules.

Know the model.

Know the price.

Set the budget.

Limit the steps.

Detect loops.

Stop retry storms.

Return structured errors.

Unknown pricing should not be treated as a harmless warning.

For agents, unknown pricing should fail closed before the provider call executes.
https://github.com/salimassili62-afk/ai-costguard

Top comments (0)