> Talon release: v1.17.0 (410f1015a621326e722ebfb0fb9e84adf2a6a6dc) > Canonical page: https://dativo.io/talon/docs/cost-governance-by-agent/ > Release source: docs/guides/cost-governance-by-agent.md > Reviewed documentation correction: 7c4389dcca6728cf22edfecd395291ba649fb7f1 > Publication details: https://dativo.io/talon/docs/publication.json # Cap AI spend for a Slack/support bot in 10 minutes If your bot or app's AI spend is growing, Talon gives you a simple promise: > You can deny requests before provider access using estimated-cost admission caps, and verify allow/deny decisions with signed evidence. Actual charges can exceed estimates; these are not invoice ceilings. This guide shows that outcome for a support-bot use case. See [budget limitations](https://github.com/dativo-io/talon/blob/410f1015a621326e722ebfb0fb9e84adf2a6a6dc/LIMITATIONS.md#7-coding-agent-and-orchestration-boundary) for estimation, reservation and recovery boundaries. --- For first-time installation, use [connect an existing application](https://dativo.io/talon/docs/add-talon-to-existing-app/) to configure `agents_dir`, credentials and the serving process. Active rules are always enforced; the legacy `gateway.mode` setting was removed in #442 and is rejected in v1.17. The abbreviated example below illustrates policy and verification, not a standalone installation procedure. ## What this guide covers - Enforced daily/monthly estimate-based admission caps for one agent (`support-slack-bot`) - Deny **before** any upstream provider call when the next request would exceed cap - Signed evidence for both allowed and denied decisions - CLI + API visibility for today/month, by agent/model/provider; session caps use estimate reservation, not a guarantee of final provider charges --- ## 1. Define the use case with admission caps The bot is one AI use case, so it gets one `agent.talon.yaml` — its Talon traffic identity and its one policy override over the organization baseline: ```yaml agent: name: support-slack-bot tenant_id: default # optional; omitted = "default" key: secret_name: support-slack-bot-talon-key # vault reference — never a raw key policies: cost_limits: daily: 10.00 # replaces the baseline daily cap monthly: 200.00 # replaces the baseline monthly cap models: allowed: ["gpt-4o-mini"] # gateway model allowlist for this agent data_classification: input_scan: true # scan-only does not override the company PII floor ``` Mint the agent key the bot will present to the gateway (the vault stores it encrypted; keep the value in your secret manager): ```bash AGENT_KEY="$(openssl rand -hex 24)" printf '%s' "$AGENT_KEY" | talon secrets set support-slack-bot-talon-key ``` The gateway side of `talon.config.yaml` holds only providers and the organization baseline (see [examples/gateway/talon.config.gateway.yaml](https://github.com/dativo-io/talon/blob/410f1015a621326e722ebfb0fb9e84adf2a6a6dc/examples/gateway/talon.config.gateway.yaml)): ```yaml gateway: enabled: true listen_prefix: "/v1/proxy" providers: openai: enabled: true secret_name: "openai-api-key" base_url: "https://api.openai.com" organization_policy: defaults: pii_action: "warn" daily_cost: 100.00 # organization baseline; the agent override above wins for this agent monthly_cost: 2000.00 constraints: max_daily_cost: 500.00 # optional org ceiling no agent override can exceed (#287) ``` The amounts are in the installation's configured cost currency; inspect the `currency` field in `talon costs --agent support-slack-bot --json`. Historical `_eur` field names are not a currency guarantee. Use a dedicated synthetic installation for denial testing. **Effective caps = one calculation path.** The caps enforcement applies are resolved by the same function that feeds `talon costs` and the `/v1/costs/budget` endpoint: organization baseline (`organization_policy.defaults.daily_cost` / `monthly_cost`) → the agent's one override (an agent cap replaces the baseline when > 0). Org budget ceilings (`organization_policy.constraints.max_daily_cost` / `max_monthly_cost`, #287) are enforced **in addition** to the resolved per-agent cap — an agent override can never raise them, and a ceiling denial names the organization in the deny reason (`budget_exceeded: request would exceed organization daily cost limit`). What you see reported is exactly what is enforced. --- ## 2. Start Talon gateway ```bash talon serve --host 127.0.0.1 --gateway --gateway-config=path/to/talon.config.yaml ``` Start it with `TALON_ADMIN_KEY` set, as in [connect an existing application](https://dativo.io/talon/docs/add-talon-to-existing-app/#1-prepare-talon-once): without the admin key the administrative endpoints accept every request, and without `--host` the server listens on every network interface. Ensure provider keys are in the vault. Give the value on stdin so it never appears in the process list or the shell history: ```bash printf '%s' "$OPENAI_API_KEY" | talon secrets set openai-api-key ``` --- ## 3. Run the 6-step demo flow 1. Start with a cap sufficient for a permitted synthetic request and confirm the configured pricing and effective caps. 2. Send one request and inspect settled usage and signed evidence. 3. In the test installation, lower the positive admission cap below the already settled spend (or below the next known estimate); wait for the new agent generation to load and verify it using `talon agents show support-slack-bot --effective`. Send a request again. 4. Verify Talon denies **before** the provider call 5. Verify signed evidence exists for the denial 6. Verify `budget_status` in the metrics snapshot reflects the event Example calls — the bot authenticates with its **agent key** (`$AGENT_KEY` from step 1). These calls are illustrative; two identical requests alone do not guarantee one allow and one deny. Use a deterministic mock for a reproducible test and inspect an independent upstream count. For released implementation coverage, see `internal/gateway/budget_enforcement_test.go` and `internal/gateway/session_budget_test.go` in the matching checkout. ```bash # Allowed request (first call) curl -sS "http://localhost:8080/v1/proxy/openai/v1/chat/completions" \ -H "Authorization: Bearer $AGENT_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Summarize ticket #123"}]}' # After the lower cap is active: repeat and check the actual decision curl -sS "http://localhost:8080/v1/proxy/openai/v1/chat/completions" \ -H "Authorization: Bearer $AGENT_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Summarize ticket #124"}]}' ``` Expected deny characteristics when the binding cap is exceeded (missing pricing or unavailable budget state are distinct errors): - HTTP 403 - Machine-readable error code/reason contains `budget_exceeded` - No upstream provider execution for the denied call - Signed evidence row recorded with denial reason and estimated pre-call cost --- ## 4. Verify with CLI and API CLI: ```bash talon costs --tenant default talon costs --agent support-slack-bot --json talon costs --by-provider --tenant default ``` `talon costs --agent` reports the agent's **effective** daily/monthly caps — resolved through the same computation enforcement uses, so the numbers can never drift from runtime behavior. `--json` emits the shared cost report (`internal/costs`): `today_eur`, `month_eur`, `seven_days_eur` with their exact UTC bounds in `window`, the day and month breakdown maps (`by_agent_eur` / `by_agent_month_eur`, or the `--by-model`, `--by-provider`, `--by-team` equivalents), `daily_budget` / `monthly_budget` with `source`, cache figures on the tenant view, and `warnings` when a secondary query failed. `currency` is the unit of every amount; the `_eur` suffixes are historical names. Export cost rows (joinable to signed evidence by `evidence_id`): ```bash talon costs export --tenant default --agent support-slack-bot --format csv talon audit export --tenant default --agent support-slack-bot --format signed-json ``` HTTP/API equivalents: - `GET /v1/costs` - `GET /v1/costs/budget?agent_id=support-slack-bot` - `POST /v1/costs/export` Real-time snapshot (requires `--gateway`): - `talon metrics` or `GET /api/v1/metrics` — `budget_status`, `agent_stats`, `model_breakdown`, `provider_breakdown` --- ## Cost visibility vs caps vs evidence attribution - **Cost visibility**: today/month totals and breakdowns by tenant/agent/model/provider - **Budget admission caps**: deny requests whose estimated cost would exceed the effective daily/monthly cap before the provider call - **Evidence-backed attribution**: every allow/deny is signed and traceable by evidence ID, including budget-denied rows with zero provider cost and denial reason This is the launch narrative connection to evidence integrity: > Verified evidence proves both governance decisions and cost attribution. --- ## Native agents (no gateway) The same `agent.talon.yaml` governs `talon run` — same file, same caps, same derived tenant: ```yaml policies: cost_limits: per_request: 0.50 daily: 20.00 monthly: 400.00 ``` --- ## Next steps | I want to… | Doc | |------------|-----| | Verify signed exports and tamper checks | [How to export evidence for auditors](https://dativo.io/talon/docs/compliance-export-runbook/) | | Understand the metrics snapshot schema | [Gateway metrics API](https://github.com/dativo-io/talon/blob/410f1015a621326e722ebfb0fb9e84adf2a6a6dc/docs/reference/gateway-metrics-api.md) | | Add more agents/models | [Configuration and environment](https://dativo.io/talon/docs/configuration/) | | Apply additional governance snippets | [Policy cookbook](https://dativo.io/talon/docs/policy-cookbook/) |