omp packages

pi-model-setting0.1.1

Per-model service tier and context window settings for Pi

davideasden Published 13 hours ago MIT ~0 downloads/mo

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.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-model-setting

A standalone extension for Pi 1.7.0. It does not modify Pi's source code, models.json, or authentication configuration.

  • /service_tier: choose default, fast, or ultrafast for models where provider === "openai".
  • /context_window: set the context window of the current physical chat model for any provider.
  • All command descriptions, selectors, results, and error messages are in English.
  • Settings are stored per provider/modelId and never shared between models.

Installation

Requires Pi 1.7.0. The package ships the TypeScript source that Pi loads directly, so there is no build step and no dist/ directory to wait for.

From Git

pi install git:github.com/DavidEasden/pi-model-setting

That tracks the repository's default branch. Pin an explicit ref when you want a fixed version; Pi reconciles the checkout to that ref and does not move it on update:

pi install git:github.com/DavidEasden/pi-model-setting@main
pi install git:github.com/DavidEasden/pi-model-setting@v0.1.0
pi install git:github.com/DavidEasden/pi-model-setting@<commit>

An HTTPS repository URL is treated as a Git source as well:

pi install https://github.com/DavidEasden/pi-model-setting

Git packages are cloned under ~/.pi/agent/git/<host>/<owner>/<repo>, and Pi installs their declared dependencies on installation. This package only declares @earendil-works/* as peer dependencies, which Pi supplies itself, so nothing needs to be installed by hand.

From npm

pi install npm:pi-model-setting
pi install npm:pi-model-setting@0.1.1

An exact version is pinned and not checked for updates; the bare name follows the latest tag.

From a local checkout

pi install .

A local package is loaded from the resolved path without being copied; run the command from the project directory, or pass an absolute path instead. The declaration is stored as a path relative to the settings file that contains it, so prefer a Git or npm source for an install that should survive moving the checkout.

Try it without changing your settings

pi -e git:github.com/DavidEasden/pi-model-setting
pi -e ./index.ts

-e leaves the installed package list untouched and caches Git sources under ~/.pi/agent/tmp/extensions/, re-checking them on every start and /reload.

Manage the installation

pi list                                          # show installed packages
pi update --extensions                           # reinstall packages and reconcile their refs
pi update git:github.com/DavidEasden/pi-model-setting   # update this package only
pi remove git:github.com/DavidEasden/pi-model-setting

Add --local (-l) to write the declaration to .pi/settings.json instead of personal settings; project packages load only after project trust is granted.

After installing, restart Pi or run /reload in an existing session. Do not add both index.ts and the whole package at the same time, since the first loads one extension file and the second loads the package.

Development and testing require Node.js 22.19 or newer.

Commands and interaction

Type a command on its own to open a searchable list:

/service_tier
/context_window
Command Options
/service_tier default, fast, ultrafast
/context_window Model default, 512k, 1m, Custom…
  • Arrow keys move the cursor; typing filters the list. The current value is marked with ✓.
  • Enter: apply to the current session and persist the choice in the session branch.
  • Ctrl+S: apply, and also save it as the default for the current model in new sessions.
  • Esc: cancel without committing a selection.
  • Saved defaults are labelled Saved default.
  • Custom… accepts integers plus k / m suffixes. Pressing Ctrl+S on that item saves the entered value as the default.
  • Navigation, confirm, and cancel use the keybindings Pi injects; Ctrl+S is specific to this selector.

You can also apply a value directly to the current session:

/service_tier default
/service_tier fast
/service_tier ultrafast
/context_window 512k
/context_window 1m
/context_window 750000
/context_window auto

There are no /tier or /ctx aliases. To save a default, use Ctrl+S in the list rather than an extra long form command.

The no-argument list is TUI-only. RPC can use the commands with arguments; print / JSON modes can apply arguments too, but Pi does not show UI notifications in those modes. The commands refuse changes while a model request, compaction, or another operation is in progress.

What the context window means

512k = 512,000 and 1m = 1,000,000, using decimal units.

Model default dynamically reads contextWindow from the current model registry. It includes the original model configuration but excludes any override applied by this extension. Choosing it is equivalent to /context_window auto:

  • removes the extension's override and follows the model configuration;
  • saving writes null, not a snapshot of the length at that moment;
  • re-syncs on model switch, reload, opening the command, or entering a request boundary;
  • if external code refreshes only the registry without emitting events, the sync happens at the next such boundary — the model registry is not polled.

The change applies to the active model's metadata, so Pi's context usage display and automatic compaction decisions use the new value. It does not change maxTokens, the thinking level, or model selection, and it never puts a context-length field into HTTP requests.

Explicit values must be positive safe integers and greater than the effective compaction reserve for the current model. Validation follows Pi's own order: compaction.modelOverrides["provider/modelId"].reserveTokens → global compaction.reserveTokens → 16,384. The check is kept even when automatic compaction is currently disabled. If a stored value is no longer valid while restoring, an error is reported and that override is not applied.

This is only a local context budget; it does not give the server a larger context capability. Set it according to the real backend limit. A smaller value also does not delete history immediately; the next normal compaction check decides whether to compact.

Limits for virtual routed models depend on the final physical model, so you cannot change the context of pi-virtual directly; switch to the physical model you want to configure first. Image generation and classification models are not chat models and are out of scope.

Service tier boundaries

Only models whose provider is exactly openai, using the openai-responses or openai-completions API, are supported. The field is not injected into Anthropic, Google, openai-codex, or any other custom provider.

The request body service_tier is set through the public before_provider_request hook:

  • sends default when no other value is selected;
  • sends fast and ultrafast verbatim, without mapping them to priority or any other value;
  • leaves all other request fields unchanged;
  • keeps the original error if the backend rejects the tier, with no silent downgrade.

Whether a tier is available, its pricing, and its limits are decided by the backend. This extension does not promise that official OpenAI or any compatible endpoint accepts ultrafast, and it does not adjust Pi's cost accounting.

In Pi 1.7.0 that hook receives only the payload, with no physical model argument. The extension verifies the current provider/API and the model ID inside the payload, so it does not force a tier onto virtual routing or onto a different model request redirected by another extension. It covers normal session requests; Pi's built-in compaction summaries, branch summaries, and standalone requests issued directly by other extensions are not guaranteed to pass through this hook.

Storage and recovery

Model defaults are stored in:

~/.pi/agent/pi-model-setting.json

When --agent-dir or PI_CODING_AGENT_DIR is used, the file follows the corresponding directory.

Example:

{
  "version": 1,
  "models": {
    "openai/gpt-5.5": {
      "service_tier": "fast",
      "contextWindow": null
    },
    "anthropic/claude-sonnet-4-5": {
      "contextWindow": 1000000
    }
  }
}

Precedence is resolved per field:

  1. a value explicitly selected in the current session branch;
  2. the saved default for that model;
  3. the context window falls back to the model's original configuration, and the service tier falls back to default.

Session values are stored with pi.appendEntry("pi-model-setting", ...) and never enter the model context. Restoring a session, reloading, deriving sessions, and tree navigation rebuild the settings from the current branch and ignore selections from abandoned branches. A --no-session session keeps session values in process memory only.

The context override on the original object is reverted when the model switches, the extension shuts down, or the extension reloads. If another extension has already rewritten that field, a stale value is not forced back. Ordinary CLI runs use a separate runtime per session; SDK hosts should not share one mutable Model object across concurrent sessions.

Saving uses a file lock, a re-read-and-merge while holding the lock, then a temporary file and an atomic replace. A corrupt configuration, unknown version, or held lock produces an error: the original file is left untouched and the selection is not applied. A concurrent save that hits the lock may retry later; if a process was killed while holding the lock, clean up pi-model-setting.json.lock in the same directory only after confirming that no other Pi is saving.

Development and verification

npm install
npm run check
npm test
npm pack --dry-run

To publish a new version, bump version in package.json, then run npm publish. npm may route the upload into staged publishing; a maintainer then approves it with 2FA, either from the Staged Packages tab on npmjs.com or with npm stage approve <stage-id> on npm CLI 11.15 or newer. Approval is what makes the version public.

The tests cover:

  • number parsing, configuration validation, branch restoration, atomic saves, and lock contention;
  • per-model isolation, dynamic original values, reversion, and registry object refresh;
  • selector search, cancel, Enter / Ctrl+S, custom input, remapped keybindings, and narrow screens;
  • the real Pi 1.7.0 SDK, verifying usage display, the automatic compaction threshold, reload, tree navigation, new-session defaults, and uninstall;
  • a local HTTP fake server verifying the actual Responses / Chat Completions request bodies, without contacting a real model service.

The runtime uses the source entry point. The published manifest contains only index.ts, src/, the README, the LICENSE, and package metadata — no resource/ reference source, session data, or test dependencies.