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 for estimation, reservation and recovery boundaries.
For first-time installation, use connect an existing application 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:
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):
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):
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
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: 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:
printf '%s' "$OPENAI_API_KEY" | talon secrets set openai-api-key
3. Run the 6-step demo flow
- Start with a cap sufficient for a permitted synthetic request and confirm the configured pricing and effective caps.
- Send one request and inspect settled usage and signed evidence.
- 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. - Verify Talon denies before the provider call
- Verify signed evidence exists for the denial
- Verify
budget_statusin 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.
# 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:
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):
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/costsGET /v1/costs/budget?agent_id=support-slack-botPOST /v1/costs/export
Real-time snapshot (requires --gateway):
talon metricsorGET /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:
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 |
| Understand the metrics snapshot schema | Gateway metrics API |
| Add more agents/models | Configuration and environment |
| Apply additional governance snippets | Policy cookbook |