@seqyuan/pimodel0.4.1
Import OpenAI-compatible model providers into PI models.json
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
pimodel
pimodel imports models from an OpenAI-compatible provider into PI's models.json.
It is a lightweight Node.js CLI with a small interactive prompt dependency and no release build step.
Install
npm install -g @seqyuan/pimodel
Usage
pimodel # fully interactive import
pimodel --help # show help
pimodel --version # print version
The tool will interactively prompt for:
| Prompt | Description |
|---|---|
| Provider | A known provider (deepseek, bailian), or a custom endpoint |
| Base URL | Only for a custom endpoint (e.g. https://api.openai.com/v1) |
| API Key | API key, hidden while typing; leave empty for local providers |
| Provider name | PI provider name to create or update |
| Models | Choose models interactively from the fetched provider catalog |
Known providers (presets)
--preset fills in the base URL, the API and the provider name, so only the key
is left to type:
pimodel --preset deepseek --api-key "$DEEPSEEK_API_KEY"
pimodel --preset bailian --api-key "$DASHSCOPE_API_KEY"
| Preset | Base URL | Notes |
|---|---|---|
deepseek |
https://api.deepseek.com |
pi already ships these models → credential-only |
bailian |
https://dashscope.aliyuncs.com/compatible-mode/v1 |
adds compat.thinkingFormat: "qwen" |
A preset marked builtIn writes only the API key, never a models array. pi
replaces a catalog model with any models entry sharing its id, so writing the
thinner entries this tool generates would strip cost, thinkingLevelMap,
inputLimits and compat from pi's own catalog. Leaving models out keeps the
catalog authoritative. --credential-only applies the same rule to any provider.
For a preset that pi does not ship, models are still discovered from the endpoint and their metadata is copied from pi's catalog by model id (see Model fields).
Scripted / non-interactive imports
Every prompt has a flag, so the CLI can run without a TTY:
pimodel --base-url https://api.openai.com/v1 \
--provider openai \
--api-key "$OPENAI_API_KEY" \
--all --dry-run
| Flag | Description |
|---|---|
--base-url <url> |
Provider base URL |
--api-key <key> |
API key; omit or pass "" for providers without auth |
--provider <name> |
PI provider name to create or update |
--api <api> |
PI API for the provider (default openai-completions) |
--models <list> |
all, numbers (1,3), ranges (1-5), or model IDs |
--all |
Import every discovered model |
--config <path> |
Alternate models.json path |
--preset <name> |
Known provider (deepseek, bailian); skips the base URL prompt |
--credential-only |
Write only the API key and keep pi's own catalog models |
--dry-run |
Print the plan and write nothing |
--replace |
Overwrite metadata of models that already exist |
--allow-settings-change |
Rebind an existing provider name to a different base URL |
--no-enrich |
Skip per-model detail endpoints |
Answers may also be piped, in prompt order:
printf 'https://api.openai.com/v1\n%s\nopenai\nall\n' "$OPENAI_API_KEY" | pimodel
Endpoint discovery
The CLI automatically tries multiple endpoint paths to fetch the model list:
/v1/models— OpenAI / most compatible providers/models/api/models/api/tags— Ollama
If a base URL is given without /v1, the stored baseUrl gains the /v1 prefix when discovery succeeded on /v1/models or /api/tags, because PI appends /chat/completions to the stored value.
Model display format
When models are discovered, the CLI renders them in this format:
Available models (14):
1. custom - unknown | out=64000
2. auto - unknown | out=64000
3. ring-2.6-1t - unknown | ctx=262144 | out=32800
4. mimo-v2.5-pro - unknown | ctx=1000000 | out=131000
5. gpt-5.3-codex - unknown | ctx=400000 | out=128000
Interactive model selection
The flow first lets you choose between importing all models or interactively selecting a subset.
Up/Down: moveSpace: select or unselect the current modelEnter: confirm selectionCtrl+C: cancel
For large catalogs, the interactive picker uses a scrollable list instead of printing every model at once.
The picker requires at least one selected model; cancelling is Ctrl+C.
Non-interactive mode
When stdin or stdout is not a TTY (e.g. piped input), the tool falls back to a prompt-based mode: it prints the model table and asks you to type all, model numbers (1,3), ranges (1-5), or model IDs.
Provider matching and re-import
A provider's identity is its base URL; the name is only a label. Matching runs in this order:
- the provider name (case-insensitive),
- an existing provider with the same
baseUrl+apiKey, - a single existing provider with the same
baseUrl— a warning is printed because its stored connection settings are replaced.
When the name matches and the base URL is the same, the stored apiKey is
overwritten (or removed by passing --api-key ""), so credentials can be
rotated in place.
When the name matches but the base URL is different, the run stops with a
SETTINGS_CONFLICT error instead of silently rebinding the provider:
Error: provider "openai" is bound to https://api.oldvendor.example/v1, but
http://127.0.0.1:8899/v1 was supplied; pass --allow-settings-change to rebind
it, or pick a different --provider name to keep both
In an interactive terminal the same situation is a confirmation prompt that
defaults to No. --dry-run previews the rebind as a warning and writes
nothing. A rebind keeps the models already stored for the old endpoint (they may
carry hand-tuned limits) and says so in the summary; models.json.bak still
holds the pre-change file.
New models are added; existing models are skipped unless --replace is given.
Output safety
models.json contains plaintext API keys, so pimodel:
- writes the file atomically (temp file + rename) — an interrupted run cannot truncate your config,
- writes it with
0600permissions, - keeps the previous version as
models.json.bak, - adds
"$schema": "https://pi.dev/schemas/models.schema.json"when the file does not have one.
Metadata enrichment
If the provider's model list does not include context window or max output tokens, the CLI automatically tries model detail endpoints (/v1/models/{id}, /models/{id}, /api/models/{id}, Ollama /api/show) to fill in the gaps, a few models at a time.
For models where detail endpoints also don't return limits, pimodel falls back to conservative values derived from the model ID (unknown models get 8k context / 4k output). Under-estimating only makes PI compact earlier; over-estimating produces rejected requests. Every estimated field is listed in the summary so you can correct it in models.json. Models whose ID suggests reasoning support (thinking, o3, deepseek-r1, …) are flagged with reasoning: true.
Output
By default it writes:
~/.pi/agent/models.json
If PI_CODING_AGENT_DIR is set, it writes ${PI_CODING_AGENT_DIR}/models.json.
Model fields
Only the fields pi actually needs are written, in the format of the current
models.schema.json:
| Field | Source |
|---|---|
id |
the id returned by the provider |
name |
the provider display name, falling back to id |
contextWindow |
detail endpoint → pi's catalog → estimate from the model id |
maxTokens |
same chain |
reasoning |
endpoint capability flags → pi's catalog → model-id pattern |
input |
endpoint modalities/vision flags → pi's catalog → model-id pattern; written as ["text", "image"] and only when image input is verifiable |
thinkingLevelMap, compat, cost, promptCache, inputLimits |
pi's catalog, when the endpoint cannot express them |
input is omitted for text-only models because pi already defaults to
["text"]. Image support is claimed only when the endpoint declares it or the
model id identifies an unambiguous vision family (-vl, vision, omni,
gpt-4o/gpt-5, claude, gemini, llava, glm-4.5v, …). An ambiguous id
stays text-only, since a wrong claim makes pi attach images the endpoint rejects.
Explicit false values from the endpoint override the id heuristics in both
directions. Provider-level compat is written once and a model-level copy that
matches it exactly is dropped. cost is copied only when all four required
sub-fields are present.
pi's catalog ($PI_CODING_AGENT_DIR/models-store.json) is read, never written;
if it is missing or unparseable the tool silently falls back to discovery and
estimates. The summary reports how many models were filled from it:
metadata: 1 model(s) filled from pi's catalog (contextWindow, maxTokens, reasoning, input, thinkingLevelMap, compat, cost)
Fields left unset stay at pi's defaults, so
samplingParams and per-model api/baseUrl are only written by hand.
Programmatic use
import { fetchModels, importModels } from "@seqyuan/pimodel";
const models = await fetchModels("https://api.openai.com/v1", process.env.OPENAI_API_KEY);
const result = await importModels({
provider: "openai",
baseUrl: "https://api.openai.com/v1",
apiKey: process.env.OPENAI_API_KEY,
fetchedModels: models,
modelIds: ["gpt-4o-mini"], // or allModels: true / modelIndexes: [1, 2]
dryRun: false,
replaceExisting: false
});
console.log(result.configPath, result.addedModels.length, result.warnings);
Other exports: parseModelList, selectModels, mergeProviderConfig, readModelsConfig, writeModelsConfig, convertToPiModels, estimateModelParams, deriveProviderBaseUrl, getModelListEndpoints, fetchModelsResult, fetchModelDetail, enrichModelsWithRemoteMetadata, getDefaultModelsConfigPath, getDefaultCatalogPath, readPiCatalog, findCatalogModel, applyCatalogMetadata, extractModelLimits, extractModelCapabilities, inferModelInput, detectProviderConflict, maskSecret, SettingsConflictError. Preset helpers (PROVIDER_PRESETS, resolvePreset, listPresets, presetNames) are re-exported from the package entry point and defined in src/presets.js.
mergeProviderConfig throws SettingsConflictError (code: "SETTINGS_CONFLICT", details on .detail) when a provider name would be rebound to a different base URL without allowSettingsChange: true. Use detectProviderConflict(config, options) to check for that situation before building a plan.