AI Agency Cost Management: Set Client Spend Limits with Odock
Map client workloads to runtime keys, review Odock budget reservations and recorded spending, and define handling for budget and quota rejections.
What you should take away
- 1Use a separate key per client workload as a proposed attribution design.
- 2Review broader matching controls alongside each workload's intended ceiling.
- 3Test the worker's pause and escalation behavior before production rollout.
- 4Keep gateway spending review separate from the broader project-margin worksheet.
To control client spending, assign a separate runtime key to each workload, associate its intended ceiling with the correct principal, and verify attribution before expanding traffic. Odock reserves estimated cost before the upstream call and settles actual cost after completion. This tutorial provides a workload register, documented budget review steps, and a local rejection-policy example; the supplied evidence does not include the complete budget-creation procedure.
What will you build to control client spending?
Build a client-to-key register, a budget configuration worksheet, and a worker rejection policy. Start with one workload and require evidence of attribution, matching controls, and worker behavior before adding others.
Odock reserves estimated cost before the upstream call and settles actual cost after completion. Odock, Budgets
Treat separate keys per workload as your implementation design. Do not assume a built-in client-account hierarchy. Keep the client mapping in your operational register.
Investigate the business premise rather than assuming it: which workloads lack owners, which consumption patterns need ceilings, and which client engagements require additional cost reconciliation?
What prerequisites and versions should you record?
Prepare the following inputs:
- Existing integration: Select one working test workload and its owner.
- Operator access: Arrange a review of keys, grants, budgets, Usage Records, and Invoices.
- Pricing review: Ask the operator to confirm the model and MCP pricing relevant to the workload.
- Version record: Record the deployed gateway release, application revision, and local Python version.
- Credential placeholders: Use
$ACME_API_KEYandhttps://gateway.example.comin deployment notes. Store no secret values in the register. - Configuration procedure: Obtain the release-specific budget-creation instructions before changing limits.
Applications call Odock with virtual API keys; upstream provider keys stay inside Odock. Odock, Virtual API Keys
The supplied evidence establishes neither a minimum gateway release nor a tested Python version. Local validation was attempted, but the execution environment failed before Python started. The example below is not presented as executed or syntax-checked.
How should you map client workloads to runtime keys?
Prepare the workload register
Use this hypothetical register. Replace labels with actual identifiers after provisioning, without recording secret values.
| Client | Workload | Proposed key label | Escalation owner |
|---|---|---|---|
| Acme | Production assistant | acme-assistant-prod | Client operations |
| Acme | Evaluation batch | acme-evaluation | Evaluation lead |
| Beacon | Production assistant | beacon-assistant-prod | Client operations |
Separate workloads when they require different stop decisions. For a client with several keys, explicitly document which controls should cover the combined workload set. Verify the principal design before treating separate key limits as a combined client ceiling.
Review scope and access separately
Scope affects attribution and matching controls; it does not grant model or MCP access by itself. Odock, Scope and principals
Ask the operator to confirm the principal chain and explicit grants for each registered key. Continue identity planning with AI agent identity and non-human identity.
How should you specify and review a spending ceiling?
Write the intended configuration
Prepare a worksheet with the intended owner, amount, currency, schedule, timezone, and escalation owner. Label it as a proposed specification until the operator verifies the saved configuration.
Documented schedule fields include Start At, Period, Timezone, End At, Rollover, and Active; periods are daily, weekly, monthly, or quarterly. Rollover is qualified as available when supported. Odock, Windows and reservations
Ask the operator to confirm rollover behavior before enabling it. The supplied documentation does not include the complete creation form or an administrative request contract. Do not convert this worksheet into an assumed API payload.
Inspect every matching window
Every active rule matching the request's principal must pass, including broader organization or team controls. Odock, Management
Follow the documented review path: identify the failed request's key, open its attached budgets, then open Budgets and filter for matching organization, team, user, and API-key budgets. Inspect each active window and compare used plus reserved consumption with its limit. Odock, Handle budget exceeded
Reserved cost represents capacity held for in-flight or unreconciled requests; used cost represents settled actual usage. The documented normal lifecycle releases unused reservation. Odock, Windows and reservations
Check a hypothetical capacity calculation
For a worksheet exercise, assume a $100 window with $80 used and $15 reserved. That leaves $5 for the illustrative next reservation. A proposed $6 reservation exceeds that remainder.
These are hypothetical inputs, not measured gateway results. Do not use this calculation as evidence that a configured limit works.
When any active matching budget lacks capacity, Odock rejects the request before the upstream call with 402 budget_exceeded. Odock, Handle budget exceeded
How should your worker handle rejected requests?
Define the stop decision
For budget exhaustion, the documentation recommends pausing work, waiting for capacity, or escalating instead of immediately retrying. Odock, Handle budget exceeded
When any active matching quota lacks capacity, Odock rejects the request before the upstream call with 429 quota_exceeded. The documentation recommends slowing down, waiting, stopping a batch, or investigating traffic while avoiding tight retry loops. Odock, Handle quota exceeded
Save this proposed policy as client_limits.py. Pass it an HTTP status and an already normalized error code. Confirm the deployed response-body contract before adding response parsing.
def next_action(status, code):
if (status, code) == (402, "budget_exceeded"):
return "pause_and_notify_owner"
if (status, code) == (429, "quota_exceeded"):
return "stop_batch_and_review_capacity"
if 200 <= status < 300:
return "continue"
return "handle_other_response"
cases = [
(200, "", "continue"),
(402, "budget_exceeded", "pause_and_notify_owner"),
(429, "quota_exceeded", "stop_batch_and_review_capacity"),
(500, "", "handle_other_response"),
]
for status, code, expected in cases:
action = next_action(status, code)
assert action == expected
print(f"{status}: {action}")Run the local checks
Run these commands in your development environment:
python3 --version
python3 -m py_compile client_limits.py
python3 client_limits.pyExpected output from the final command, not observed execution output:
200: continue
402: pause_and_notify_owner
429: stop_batch_and_review_capacity
500: handle_other_responseImplement the actual pause, notification, and batch-stop effects in your worker. Test that queued work remains paused and that an owner receives the escalation. The local function only selects action names.
How do you verify attribution and recorded spending?
Inspect one controlled request
Use your existing verified integration to send one request within an approved test allowance. Record the workload, key identifier, response status, and available request identifiers.
Usage records include the principal, provider, model, status, latency, request ID, tokens, USD cost, and routing trace. Recording is asynchronous, so records may appear a few seconds after the response. Odock, Usage Records
Expected review result: the recorded API key and owner chain match the workload register. Investigate mismatches before expanding traffic.
Review and export the selected period
The Invoices interface reads stored usage, supports period, team, and API-key filters, and exports PDF summaries or detailed CSV records. Missing model or MCP pricing can leave costs incomplete. Odock, Invoices
Open Invoices, select the period and registered keys, and review the preview. Choose Download CSV (all records) for detailed records. Expected review result: the selected period and keys match the worksheet. Odock, Invoices
MCP calls appear in the shared usage table under provider = mcp; their Cost total already includes the MCP-specific contribution. Odock, MCP usage records
Avoid counting that contribution twice. For project-margin review, maintain a separate worksheet for revenue, delivery labor, hosting, external tools, and support. Do not label the gateway export as your complete profitability report.
Verify actual enforcement separately
Arrange a controlled exhaustion test with the operator after confirming the creation procedure and test allowance. Require an observed rejection, the expected worker pause, and an escalation record.
Do not treat the local policy assertions as proof of gateway enforcement. Preserve application and gateway evidence for the same test request.
What should you check when results look wrong?
- Forbidden model or tool: Review explicit grants separately from key scope. Scope and principals
- Unexpected budget rejection: Inspect every active matching window, including broader controls. Handle budget exceeded
- Missing recent record: Allow for asynchronous persistence, then refresh. Usage Records
- Incomplete spending: Review period filters and configured pricing. Invoices
- Capacity still reserved: Review reservations separately from settled usage. Windows and reservations
For unexplained settlement after cancellation, failure, or interrupted streaming, preserve request evidence and ask the operator to establish the expected lifecycle. The supplied evidence does not resolve those cases.
What should you complete before adding another client?
Require a register entry matched to request evidence, verified saved budget settings, a review of all matching windows, an observed worker stop, and a spending export checked for pricing gaps.
Continue with virtual keys, budgets, and quotas and production logging and tracing.
Sources
- Odock, Virtual API Keys, publication date not supplied.
- Odock, Scope and principals, publication date not supplied.
- Odock, Management, publication date not supplied.
- Odock, Budgets, publication date not supplied.
- Odock, Windows and reservations, publication date not supplied.
- Odock, Handle budget exceeded, publication date not supplied.
- Odock, Handle quota exceeded, publication date not supplied.
- Odock, Usage Records, publication date not supplied.
- Odock, Invoices, publication date not supplied.
- Odock, MCP usage records, publication date not supplied.
What you should take away
- 1
Use a separate key per client workload as a proposed attribution design.
- 2
Review broader matching controls alongside each workload's intended ceiling.
- 3
Test the worker's pause and escalation behavior before production rollout.
- 4
Keep gateway spending review separate from the broader project-margin worksheet.
Frequently asked questions
Does a team-scoped key automatically grant model access?
Scope affects attribution and matching controls; it does not grant model or MCP access by itself.
Why can a request fail when its key budget has capacity?
Every active rule matching the request's principal must pass, including broader organization or team controls.
Should a worker immediately retry budget exhaustion?
For budget exhaustion, the documentation recommends pausing work, waiting for capacity, or escalating instead of immediately retrying.
Review one client workload
Bring your workload mapping, intended spending ceiling, and rejection-handling requirements to a demo.
Related articles
How to Control LLM Costs with Virtual API Keys, Budgets, and Quotas
The fastest way to lose control of AI economics is to let every service hit providers directly with shared credentials. This article shows the operational model teams need instead.
Read articleAI Agents Are Non-Human Identities Now: The 2026 Credential Sprawl Problem
Your AI agents are not features. They are non-human identities, they hold credentials, they act autonomously, and most security teams have no lifecycle for them at all. Here is why NHI sprawl became 2026's quiet agentic AI risk, and what fixing it actually requires.
Read articleWhat to Log, Monitor, and Trace in Production LLM Applications
When AI traffic crosses providers, tools, tenants, and teams, observability has to connect quality, latency, cost, safety, and routing decisions.
Read article