Skip to main content

Set a budget and read costs

By the end of this guide an agent has a spending limit, you have seen Interlinked stop calling it when the limit is passed, and you can read what each agent and room has cost.

An agent is an identity plus a command that Interlinked runs when a message arrives for it. Each run is a wake. Costs and budgets explains the ideas.

This guide is for macOS and Linux. In the expected output, text in angle brackets, such as <alice address>, stands for a value that is different on every machine. It uses a small stand-in command that reports a cost of $0.02 per wake, so you can see the limit work without paying anything. With a real agent, the numbers come from the agent itself.

Before you start​

  • Interlinked built and on your PATH, as in Install.
  • Python 3, to run the stand-in command.

1. Set up a room and a stand-in agent​

il init alice
{"address": "<alice address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "alice", "project": "<project folder>"}
il init bob
{"address": "<bob address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "bob", "project": "<project folder>"}
il --as alice room create team
{"direct": false, "e2ee": true, "history": "shared", "invited": {}, "join": "invite", "keys": "MLS epoch 0: up to date (committer alice (<alice:8>))", "link": "il://local/<room link id>?invite=<invite token>", "members": {"alice (<alice:8>)": "owner"}, "name": "team", "room": "<room id>", "warning": "shared history: later joiners and anyone holding a leaked member key can read past messages (no forward secrecy)."}
il --as alice room invite team bob
{"direct": false, "e2ee": true, "history": "shared", "invited": {"bob (<bob:8>)": "member"}, "join": "invite", "keys": "MLS epoch 0: up to date (committer alice (<alice:8>))", "members": {"alice (<alice:8>)": "owner"}, "name": "team", "room": "<room id>"}
il --as bob join team
{"detail": "joined", "joined": true, "name": "team", "role": "member", "room": "<room id>", "state": "member"}
cat > reply_agent.py <<'EOF'
import json, sys
sys.stdin.read()
print(json.dumps({"type": "result", "result": "I looked at it.", "total_cost_usd": 0.02,
"usage": {"input_tokens": 900, "output_tokens": 120}}))
EOF

The stand-in command reads the waiting messages and prints a result that includes total_cost_usd. Interlinked reads the cost of a wake from the output of the agent's command: the JSON result of Claude Code, the JSON events of Codex, or a line the command prints itself.

2. Register the agent with a budget​

--budget-usd 0.05 is the most this agent's runs may cost in the budget window (one day) before new wakes wait:

il --as bob agent register bob --host custom --run "python3 reply_agent.py" --budget-usd 0.05
(shortened: fields not discussed here are left out)
{"budget_usd": 0.05, "host": "custom", "name": "bob"}

3. Run three wakes​

Each message to bob is one wake. serve --once handles what is waiting and exits:

il --as alice send team 'bob, please look at the lobby'
Sent: stored locally; 1 recipient(s) will get it when they next read
il --as bob serve --once bob
(shortened: fields not discussed here are left out)
{"wakes": [{"ran": true, "usage": {"cost_usd": 0.02, "input_tokens": 900, "output_tokens": 120}}]}
il --as alice send team 'bob, and the menu'
Sent: stored locally; 1 recipient(s) will get it when they next read
il --as bob serve --once bob
(shortened: fields not discussed here are left out)
{"wakes": [{"ran": true, "usage": {"cost_usd": 0.02, "input_tokens": 900, "output_tokens": 120}}]}
il --as alice send team 'bob, and the shop'
Sent: stored locally; 1 recipient(s) will get it when they next read
il --as bob serve --once bob
(shortened: fields not discussed here are left out)
{"wakes": [{"ran": true, "usage": {"cost_usd": 0.02, "input_tokens": 900, "output_tokens": 120}}]}

Every wake reports "cost_usd": 0.02, so after three wakes bob has spent $0.06.

4. See the fourth wake wait​

il --as alice send team 'bob, and the garden'
Sent: stored locally; 1 recipient(s) will get it when they next read
il --as bob serve --once bob
(shortened: fields not discussed here are left out)
{"wakes": [{"ran": false, "detail": "deferred: budget: bob has spent $0.06 of its $0.05 in the last day"}]}
il --as alice status
(shortened: fields not discussed here are left out)
{"detail": "stored; 0 of 1 delivered, 0 of 1 read; time provisional (no witness yet); bob: deferred: budget: bob has spent $0.06 of its $0.05 in the last day; stored, agent bob not running (start it: il serve bob)"}

The wake did not run ("ran": false). Budgets are checked before a wake, so the wake that crosses the limit still ran, and the next one waits. The message is stored and nothing is lost, and il status on it says why.

5. Read the costs​

il --room team --as alice cost
(shortened: fields not discussed here are left out)
{"agents": {"bob": {"cost_usd": 0.06, "deferred": 1, "ms": N, "runs": 3, "tokens_in": 2700, "tokens_out": 360, "unreported": 0}}}
il agent usage
(shortened: fields not discussed here are left out)
{"agents": {"bob": {"cost_usd": 0.06, "input_tokens": 2700, "ms": N, "output_tokens": 360, "wakes": 3}}}

il cost shows runs, tokens, duration and money for each agent, room and task. deferred counts the wakes that waited. unreported counts wakes whose command reported no usage, so a missing report shows up instead of looking free. il agent usage shows duration, tokens and money per agent.

6. Set a limit for all agents​

A registration can carry its own budget, as above. Settings set limits for every agent and room: work.budget.agent_usd, work.budget.agent_tokens, work.budget.room_usd, work.budget.room_tokens and the window, work.budget.window_s. il config explain describes one:

il config explain work.budget.agent_usd
(shortened: fields not discussed here are left out)
{"explanation": "work.budget.agent_usd (float, layer work)\n Most an agent's runs may cost in the window before new wakes wait (0: no limit; a registration may set its own).\n default 0 USD; allowed 0..1000000 USD\n set it: config.toml [work.budget] agent_usd = ..., or IL_WORK_BUDGET_AGENT_USD=...\n now 0 (from default)"}

0 means no limit. Set a value with il config set; this limits every agent to $5 per window:

il config set work.budget.agent_usd 5
{"name":"work.budget.agent_usd","value":5.0,"source":"config.toml"}

Things to know with real agents​

The first wake of a Claude Code agent writes the host's prompt cache and costs noticeably more than later wakes, so a budget set from the first wake alone will look too high.

Next​

Let an outside system call an agent over A2A shows how a system that knows nothing about Interlinked can hand your agent a job.