@thruput/pi0.2.0
Routes pi's calls to Anthropic and OpenAI through Thruput.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
@thruput/pi
Routes pi's calls to Anthropic and OpenAI through Thruput, so each call is recorded against your organization and your pi session.
Install
pi install npm:@thruput/pi
Then, in pi:
/thruput login
A code and a link appear, and your browser opens the link. Approve the
sign-in. The extension stores its state in ~/.pi/agent/thruput.json, mode
0600, and from then on routes calls through Thruput.
What is routed
Calls to the anthropic and openai providers go through the Thruput
proxy. Pi keeps its own models and its own provider credentials: only the
provider's base URL changes, and the Thruput token travels in a request
header.
Every other provider stays direct. ChatGPT sign-in (openai-codex) is not
routed.
A model whose base URL was changed in models.json or by another extension
is not routed, and gets no Thruput header.
What is sent
Besides the calls, the extension posts hook events to the Thruput API: the start and end of the session, each prompt you submit, the start and end of each tool the model runs with the tool's name and outcome, and the start of a subagent session. Each event carries the work directory's GitHub repository, branch, commit, and top-level directory. The prompt text and the tool's input and output are never read. A post that fails is dropped; it never slows or stops pi.
Commands
| Command | Does |
|---|---|
/thruput, /thruput status |
Shows the state, the context, the organization, the proxy, the session, and health. |
/thruput login |
Signs into the current context and starts routing. |
/thruput logout |
Revokes the current context's token and stops routing. |
/thruput off |
Stops routing. The token stays. |
/thruput on |
Starts routing again. |
Contexts
A context is a named pair of origins, an API origin and a proxy origin, the
same as in the Thruput CLI. production is built in. Each context holds its
own sign-in, so a production and a local sign-in coexist.
| Command | Does |
|---|---|
/thruput context add <name> <api-url> [proxy-url] |
Saves a context. The proxy origin defaults to the API origin. |
/thruput context use <name> |
Makes it the default and routes through it. |
/thruput context list |
Lists the contexts, the current one marked *. |
/thruput context remove <name> |
Deletes a saved context. Run /thruput logout in it first. |
An origin is scheme and host only. HTTP is accepted on a loopback host only.
To develop against a local Thruput stack:
/thruput context add local http://api.localhost:8828 http://127.0.0.1:8827
/thruput context use local
/thruput login
/thruput context use production switches back without a new sign-in.
Environment
| Variable | Effect |
|---|---|
THRUPUT_CONTEXT |
Selects the context. Wins over the saved default. |
THRUPUT_TOKEN |
Wins over the selected context's token. |
THRUPUT_API_URL |
Wins over the selected context's API origin. |
THRUPUT_PROXY_URL |
Wins over the selected context's proxy origin. |
PI_CODING_AGENT_DIR |
Where thruput.json lives. Default ~/.pi/agent. |
THRUPUT_PI_ROOT_SESSION_ID |
Set by a parent pi; read at load. Names the root session. |
THRUPUT_PI_SESSION_ID |
Set by a parent pi; read at load. Names the parent session. |
The extension sets the last two for its child processes, so a pi that a subagent or a bash tool starts is recorded under this session.
Subagents
A child pi process inherits the two session variables and is recorded as a
child session. This covers a pi run from the bash tool and pi-subagents
background children (async: true), which run in their own process and
load this extension by themselves.
A pi-subagents foreground child is a second session inside the parent's process. Pi-subagents gives it the parent's provider registration, so its calls go to the proxy, but it does not load the parent's extensions, so the calls carry no Thruput headers and the proxy refuses them. List this extension in the agent's frontmatter so the child loads it:
subagentOnlyExtensions: ~/.pi/agent/npm/node_modules/@thruput/pi/src/index.ts
Two copies of the extension in one process share one lineage: the first session owns the environment, and the child is recorded under it. In a pi-subagents runner process, which hosts the children of one fan-out, every session is recorded as a sibling under the pi that launched it.
Remove
pi remove npm:@thruput/pi
Run /thruput logout in each signed-in context first to revoke its token,
then delete ~/.pi/agent/thruput.json.