Agent orchestrators
An orchestrator such as SpaceMan starts many agent runs, each one a coding tool with its own task. Giving every run the same long-lived token makes it impossible to tell runs apart and dangerous to leak one. Harbor Pilot instead lets the orchestrator create a run token for each run: short-lived, narrower than its parent, and carrying references that identify the run.
Status
Run tokens are contract-tested (TestMintChildConfinesBoundRefs, TestMintChildRecordsParentAsCreator, the SpaceMan acceptance scenario and TestDemoSpaceManRunsBindingAcceptsPerRunRefs against the demo seed). SpaceMan does not create run tokens yet; this page describes the Harbor Pilot side, which any orchestrator can use.
How it works
- Create a client for the orchestrator, for example
spaceman-runs, with a routing plan, a project and limits. - Create one token for it with the Create run tokens permission (
tokens:mint), and keep that token on the orchestrator's central server. Agents never see it. - When a run starts, the orchestrator creates a run token and hands it to that run only.
- When the run ends, the orchestrator revokes it. The expiry is a backstop.
Create a run token
curl https://pilot.example.com/v1/harbor/credentials \
-H "Authorization: Bearer $PARENT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "run run_01JD…",
"scopes": ["gateway:invoke"],
"ttl_seconds": 7200,
"bound_refs": {"spaceman.space": "spc_…", "spaceman.run": "run_01JD…", "session": "run_01JD…", "project_id": "prj_…"}
}'The answer is 201 Created with the credential's details and its token, shown this once:
{
"credential": {
"id": "crd_…",
"binding_id": "cbn_…",
"parent_id": "crd_…",
"scopes": ["gateway:invoke"],
"bound_refs": {"project_id": "prj_…", "session": "run_01JD…", "spaceman.run": "run_01JD…", "spaceman.space": "spc_…"},
"created_by": "crd_…",
"expires_at": "…"
},
"token": "hpk_…"
}| Field | Meaning |
|---|---|
name | Required, 1–80 characters. Shown on the client's Access tokens tab. |
scopes | A subset of the parent's, never tokens:mint. Defaults to sending requests and listing models. |
ttl_seconds | Lifetime. Defaults to 12 hours, at most 7 days, and never longer than the parent's. |
bound_refs | References tied to the token, as key: value strings. |
check_budget | Optional, default false. When true, refuse with 429 if a blocking budget the run would spend under is used up. See Budgets. |
bound_refs in the answer are the references stored on the run token: the parent token's own references plus the ones you sent. References configured on the client are not copied in; they are added to each request (see below). created_by is the parent token's id, so the client's Access tokens tab and the audit log show which token created each run token.
A run token belongs to the same client as its parent, so it uses the same plan, limits and allowed models. It can't create further tokens.
Bound references
References bound at creation are trusted: an authenticated orchestrator set them, and the agent can't change them. Harbor Pilot records them on every request the token makes.
| Key | Effect |
|---|---|
run, spaceman.run or ci.job | The run reference on each usage entry, so spend adds up per run. |
session | Groups the run's requests into one session, with high confidence. Find its session id with ref=session:<value>. |
project_id | Charges the run to a project. It must be the client's project or one of its allowed projects. |
| anything else | Recorded as a trusted reference for reporting, for example spaceman.space. |
A run token carries the parent's references, copied in when it is created. The references configured on the client (under the client's References setting) are applied when each request is made, for every key the token doesn't bind itself. A run token can add references, but it can't change either kind: sending a key the parent or the client already sets, with a different value, is refused with 400. Sending the same value is accepted.
So configure on the client only what every run shares, for example spaceman.fleet, and bind what differs per run (spaceman.space, spaceman.run, project_id) when you create the run token. A client that pins spaceman.space can serve only that one space.
Every trusted reference, whatever its key, can filter and group usage and activity (see below).
Headers the agent sends, such as X-HP-Session or X-HP-External-Ref, are hints. They are recorded as claims next to the trusted references, and never decide access or billing.


Hand the token to the run
Give the run its token like any other tool, in the run's environment:
# Claude Code
ANTHROPIC_BASE_URL=https://pilot.example.com
ANTHROPIC_AUTH_TOKEN=hpk_… # the run token
# Codex
HARBOR_PILOT_TOKEN=hpk_…
codex -c model_provider=harbor-pilot \
-c model_providers.harbor-pilot.base_url=https://pilot.example.com/v1 \
-c model_providers.harbor-pilot.wire_api=responses \
-c model_providers.harbor-pilot.env_key=HARBOR_PILOT_TOKEN …An agent with shell access can read anything in its environment, the run token included. That is why run tokens are short-lived, limited to sending requests, and tied to one run: a leaked run token is worth one client's plan for a few hours, and its requests are all labelled with the run.
Revoke it
curl -X DELETE https://pilot.example.com/v1/harbor/credentials/crd_… \
-H "Authorization: Bearer $PARENT_TOKEN"Either the parent token or the run token itself may revoke a run token; the answer is 204 No Content. Any other token gets 404.
Budgets
Send "check_budget": true when creating a run token to refuse the run before it starts. This is the authoritative pre-launch check: it reads budgets the same way as GET /api/v1/budgets/status and the request path, at the moment of the mint. If an enabled blocking budget the run would spend under is used up, the answer is 429 with code budget_exceeded, the budget's name and id in message, and budget_id, and no token is created:
{"error": {"message": "budget runs-daily is exhausted for this day (0.00105 of 0.001 USD) (bdg_…)", "type": "insufficient_quota", "param": null, "code": "budget_exceeded", "budget_id": "bdg_…"}}The budgets checked are the ones on the client, on the run's project (the project_id you bind, otherwise the client's project), on that project's workspace, and global ones. Budgets on provider accounts aren't checked, because the account is picked per request. A run that passes can still be refused on a request, when that request's own estimated cost would go over a budget, or when routing picks an account whose budget is used up.
Budgets don't apply to local or free accounts. When the client's routing plan can only reach those (for example, its restrictions allow only local and free billing), check_budget doesn't refuse the mint. Otherwise it can't tell which account a run will use, so it counts the budgets even if every request would go to a local model. If the check can't read usage, the mint fails with a 502 and the message could not check budgets; retry it or create the token without check_budget. A refused mint writes no audit entry and sends no event: the budget's own budget.threshold.exceeded was already sent when it ran out.
Without check_budget (the default), creating a run token does not check budgets: a run token is created even when a blocking budget that covers the client or its project is already used up. Its requests are then refused with 429 and the error code budget_exceeded, the first time it is used.
To follow budget refusals:
budget.threshold.exceededis sent once per budget period, when the budget is first used up.access.request.blockedis sent for every request a blocking budget refuses, with the budget inreason. The request shows as Blocked in Requests.
To see every budget's state, open Limits or call GET /api/v1/budgets/status.
See the runs
Runs show up like any other client's traffic: under the orchestrator's client, in Requests, and in Spend. To tell them apart in the UI:
- Spend → Group by → Run gives one row per run with its own requests, tokens and cost; click a row for that run's requests. Filter by reference narrows the page to one run or space. See Spend.
- Requests → More filters → Filter by reference lists one run's requests, for example Run: run_42. A request's Verified context links to All requests with this run. See Requests.
Both views keep their filters in the page address, so you can link to a run.
Through the API, filter and group by trusted references with an API token (hpa_…) that has usage.read and activity.read:
# Per-run totals in one space, one group per run (paged with cursor and limit)
curl -sS "https://pilot.example.com/api/v1/usage/summary?ref=spaceman.space:spc_alpha&group_by=ref:spaceman.run" \
-H "Authorization: Bearer $API_TOKEN"
# One run's requests
curl -sS "https://pilot.example.com/api/v1/activity/requests?ref=spaceman.run:run_a" -H "Authorization: Bearer $API_TOKEN"
# The session id of a run's bound session
curl -sS "https://pilot.example.com/api/v1/activity/sessions?ref=session:run_a" -H "Authorization: Bearer $API_TOKEN"Only trusted references count: headers an agent sends never move usage between runs. Add binding_id= when other clients could use the same reference values. See Usage and activity by reference.


The demo has a spaceman-runs client with the Create run tokens permission, if you want to try this locally. It pins only spaceman.fleet (fleet_synthetic) and allows the web-app and data-pipeline projects, so each run token can bind its own spaceman.space and project_id. The demo's two runs were made with run tokens that bind spaceman.space and their own spaceman.run (run_synthetic_1 and run_synthetic_2). See Try the demo.
With Terraform
The Terraform provider can create the Harbor Pilot side (project, client, plan and the parent token); its examples/scenarios/07-spaceman-integration shows a complete setup. See Terraform.