pi-ifm0.2.0
IFM (Institute of Foundation Models) provider for Pi: live model discovery, native auth, and OpenAI-compatible streaming.
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
pi-ifm
pi-ifm connects Pi to the IFM hosted API at https://api.ifm.ai/v1. It finds the chat models that your API key can use, stores that list for offline startup, and streams through Pi's OpenAI Completions adapter. You do not need to edit models.json.
Install
pi install git:github.com/iamaamir/pi-ifm
Try it without installing:
pi -e git:github.com/iamaamir/pi-ifm
Authenticate
Set an environment variable. IFM_API_TOKEN is checked first, then IFM_API_KEY:
export IFM_API_KEY="IFM-..."
Or log in once inside Pi:
/login ifm
Pi stores the credential in its normal credential store. pi-ifm does not log or write the key anywhere else.
Use
After authentication, IFM models appear in the standard model picker:
pi --list-models ifm
/model
Select a model and start working. Model discovery runs at startup, after login, and when you refresh. Discovery does not run for each chat message.
Commands
| Command | Purpose |
|---|---|
/ifm status |
Show credential readiness, catalog freshness, model count, compatibility state, and discovery errors. |
/ifm refresh |
Force a live catalog refresh. Keeps the last catalog if the request fails. |
/ifm config |
Configure the IFM base URL interactively. Reload or restart Pi after changing it. |
Model discovery
pi-ifm reads the authenticated GET /v1/models endpoint. For every entry that is not an obvious non-chat family (speech, embeddings, and so on), it confirms chat support with a one-token /chat/completions probe. Model IDs are used exactly as IFM returns them.
The successful catalog is cached by Pi and restored on the next launch, so Pi started without network still shows the last known models. A failed or empty refresh never replaces a healthy catalog.
IFM's model list does not publish output limits, prices, or per-model capabilities. Known models use their documented context windows; other models use conservative defaults. You can override any field per model through models.json if your account needs different limits.
Wire compatibility
Verified against api.ifm.ai:
- Text-only user content arrays are converted to strings. IFM rejects typed content arrays with
Invalid value for 'messages.content'. storeis disabled (supportsStore: false).- The unsupported
developerrole is disabled (supportsDeveloperRole: false). - Reasoning effort is sent as a top-level
reasoning_effortfield. IFM's hosted endpoint currently loops when asked formediumreasoning, so Pi's defaultmediumis mapped to IFMlow;highand above map to IFMhigh. Use/think highfor deeper reasoning. - Every replayed assistant message includes a thinking field.
reasoning_contentis the canonical field. An empty string is valid. A missing or null field causes a 400 error. - Traces are replayed verbatim, so multi-turn history stays consistent.
- Session routing uses one stable
X-Session-IDfor the whole conversation. - The base URL can be changed with
IFM_BASE_URLor/ifm config. - System, assistant, tool-call, and tool-result messages are passed through unchanged, so tool-call correlation IDs and multi-turn history are preserved.
- Image and multimodal input are not supported by IFM.
pi-ifmfails with a clear error instead of silently dropping the attachment. thinking_token_budget,tool_call_format, andtool_presentation_formatwere tested and are rejected by the current API, so they are not sent.
Pi's own streaming, tool-call parsing, usage accounting, cancellation, and retry handling are used unchanged. Streaming tool calls, tool results, follow-up completions, and cancellation were verified live against the hosted API.
Diagnostics
If an IFM response identifies a model different from the one Pi requested, /ifm status and a one-time warning explain the mismatch. The requested model id is never silently rewritten.
Known limitations
GET /v1/modelspublishes no per-model metadata. Known models use documented context windows; other models use conservative defaults (131,072-token context, 32,768 output tokens, zero cost). Override a model inmodels.jsonto change these.- IFM chat models return a
reasoningfield and support tool calling; both are enabled for every discovered chat model. /login ifmandIFM_API_KEYboth work in a normal Pi session. Use/ifm statusto check auth.
Development
npm install
npm test
npm run typecheck
Tests use mock HTTP fixtures for discovery, refreshes, malformed responses, catalog outages, request normalization, and command behavior.
License
MIT