Skip to main content

How to stop AI coding agents from running up a surprise API bill?

Summary

  • Set spend limits before the agent starts: soft thresholds that ask first, a hard limit, caps on tool calls and stuck loops, and a central cap for the team.
  • In Omnigent, the cost_budget policy tracks a session's cumulative LLM spend, pauses for approval at each soft threshold, and at the hard limit blocks expensive models until you switch to a cheaper one with /model.
  • That hard limit is a downgrade gate, not a stop. For a hard stop on every model, the builtin reference documents user_period_cost_budget with expensive_models omitted.
  • On Databricks, model calls made with workspace credentials route through Unity Gateway, so its budgets, rate limits and usage table apply too. The open-source project lists "Status: alpha"; on Databricks, "Omnigent is in Beta".

How to stop AI coding agents from running up a surprise API bill?

Put spend limits in front of the agent before it starts. With Omnigent, an open-source meta-harness for coding agents, policies check every action and allow it, block it, or pause to ask you. A session budget warns at soft thresholds and blocks expensive models at its hard limit, a tool-call cap stops runaway loops, and a server-wide policy budgets each user's daily spend. The main caveat: cost_budget downgrades at the limit instead of halting all work, so pair it with call limits or a period cap.

Why do coding-agent bills surprise people?

Spend follows tokens. Long sessions carry more context on every turn, sub-agents multiply model calls, and a stuck agent can retry the same failing command. A guardrail has to act while the session runs.

Which cost controls does Omnigent provide?

Control What it does At the limit
cost_budget Tracks a session's cumulative LLM spend; ask_thresholds_usd sets soft checkpoints Blocks the expensive_models tiers until you switch with /model
user_daily_cost_budget Same gating on one user's spend across all sessions for the current UTC day Same downgrade gate
user_period_cost_budget Same, over a day, week, month, quarter or year Omitting expensive_models blocks every model
subagent_cost_budget Gates one sub-agent on its own subtree spend Blocks expensive models
max_tool_calls_per_session Counts tool calls (limit defaults to 100) Denies further calls for the rest of the session
detect_loop Spots an identical tool call repeating Asks for approval
detect_thrashing Watches for consecutive errors or a high error rate Asks by default, or denies
deny_trivial_to_expensive_model Classifies messages as trivial or complex with the server LLM Denies trivial messages on expensive models

How do you set a budget?

Add policies to an agent's YAML file:

policies:
  budget:
    type: function
    handler: omnigent.policies.builtins.cost.cost_budget
    factory_params:
      max_cost_usd: 5.00
      ask_thresholds_usd: [3.00]
  cap_calls:
    type: function
    handler: omnigent.policies.builtins.safety.max_tool_calls_per_session
    factory_params:
      limit: 50

For a running session, open the session info panel and add the Session Cost Budget policy, or ask the agent to limit the session's spend; it configures the policy and asks for your approval. Admins can set a per-user daily budget for everyone in the server config and start the server with omnigent server -c config.yaml:

policies:
  user_daily_cost_guard:
    type: function
    function:
      path: omnigent.policies.builtins.cost.user_daily_cost_budget
      arguments:
        ask_thresholds_usd: [10.0, 25.0]
        max_cost_usd: 50.0

How do policy levels stack?

Session policies are checked first, then the agent's YAML policies, then server-wide policies, and all three levels are enforced at once. Server-wide policies apply to every session, and a DENY from any policy short-circuits the rest. Admins can change server-wide policies at runtime from the Settings page at /settings/policies or the /v1/policies REST API, without a restart.
Budgets are checked before each model turn and at each tool call, so a turn that's already running can push spend past a cap before the next check.

When should you use each control?

  • Team default: a server-wide user_daily_cost_budget.
  • Stuck agents: detect_loop and detect_thrashing, backed by max_tool_calls_per_session.
  • Unattended runs: scheduled tasks (Automations) accept max_cost_usd, a per-firing budget attached to each run's session.
  • New agents: start with soft thresholds only to see where spend concentrates before you block anything.

How Databricks approaches cost governance

On Databricks, a Databricks Sandbox host (Beta), or a harness you set up with Databricks credentials, sends model calls to the Foundation Model APIs through Unity Gateway, and the quickstart says usage is governed and billed there. Its controls then apply:

  • Budgets scoped to Unity Gateway set shared or per-user monthly thresholds that send an alert or block usage. Enforcement is near real-time but approximate, and the docs say not to rely on it as an absolute cap on billed amounts.
  • Rate limits set requests-per-minute (QPM) and tokens-per-minute (TPM) limits on a model service, with per-user defaults and custom limits for users or groups.
  • Usage tracking records token usage for each request in the system.ai_gateway.usage system table.

The managed service supports Omnigent's built-in policies and custom policies written in Common Expression Language (CEL); custom Python policies aren't supported.

FAQs

What happens when an agent hits its spending limit?

With cost_budget, further turns and tool calls on expensive models are denied, and the agent tells you what happened. Switch to a cheaper model with /model to continue, or stop there.

Can I let a session keep going past a soft threshold?

Yes. Each soft threshold asks once; approve to continue, or reject to stop that call.

How do I see where the spend went?

Turn on the usage page (OMNIGENT_FEATURES=usage_page) for a daily cost timeline and cost by harness, model and session. On Databricks, query system.ai_gateway.usage.

Do personal subscription logins count toward Unity Gateway budgets?

No. Omnigent's Databricks guide notes that consumer subscriptions use a per-user OAuth flow the gateway can't proxy, so those sessions sit outside workspace cost tracking.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.