Skip to main content
Corvex Token Factory connects to the pi coding agent as a custom provider on the OpenAI-compatible Chat Completions API. You declare the provider and its models in pi’s models.json, and set per-model compaction in its settings.json. Verified with pi 1.2.0, October 2026.

Prerequisites

  • A Token Factory API key. See Authentication.
  • pi 1.2.0 or later (npm install -g @earendil-works/pi-coding-agent; requires Node.js 22.19 or later).
  • A model from the Token Factory catalog.

Context window and compaction

pi does not read limits from the endpoint, so each model declares them:
  • contextWindow is the model’s context_window.
  • maxTokens is the output reservation pi sends with every request (as max_completion_tokens), reduced only when the context is nearly full. The example keeps pi’s default of 16,384. Setting it to the model’s full output cap would make every request reserve almost the entire window.
  • pi compacts the conversation once it exceeds contextWindow − reserveTokens, where reserveTokens is a compaction setting.
A single turn with large tool results can push the context past the compaction point before compaction runs, so leave about 15% headroom: the compaction window is (context_window − max_tokens) / 1.15, rounded down, and reserveTokens is the context window minus that value: GET /v1/models reports each model’s current context_window and max_output_tokens.
1

Store the API key

Export the key in your shell profile. models.json reads it with $CORVEX_API_KEY; a bare variable name without $ is sent as the key itself.
2

Add the provider and models

Add the provider to ~/.pi/agent/models.json:
models.json
cost is in US dollars per million tokens and only affects pi’s cost display; see Pricing for current rates.
3

Set the default model and compaction

Add these keys to ~/.pi/agent/settings.json:
settings.json
defaultModel takes the bare model ID; the provider goes in defaultProvider.
4

Run pi and verify the connection

pi --list-models corvex prints the context window and output reservation pi loaded for each model. To run one prompt non-interactively:

Compatibility notes

  • Reasoning. Both models reason before answering. Reasoning tokens count toward maxTokens; raise it if responses are cut off, and recompute reserveTokens with the formula.
  • Context length. If a session still exceeds the model’s window, the gateway returns context_length_exceeded, and pi compacts and retries. See Errors.
  • Input types. Neither model accepts image input; keep input set to ["text"].
  • Connect OpenCode — another terminal coding agent on the OpenAI-compatible surface.
  • Use the OpenAI SDK — the same endpoint from Python or TypeScript.
  • Errors — authentication, rate-limit, and validation responses.
Last modified on October 23, 2026