@mupt-ai/pi-ai. Pi translates normalized router requests into provider API calls and converts output back into the framework’s completion or stream contract.
Supports OpenAI, Anthropic, Google, Bedrock, OpenRouter, Fireworks-hosted models, and any OpenAI-compatible API in Pi’s catalog.
Inject Credentials
- Single Key
- Per Provider
When all models use the same credential:
Declare Catalog Models
pi.model() validates a model exists in Pi’s catalog and creates a RouterModel declaration:
What Gets Translated
Pi carries these normalized features into provider calls:- Messages, images, tool calls, tool results
- Prior-turn reasoning and hosted
web_searchcalls - Function tools, named/required tool choice, strict/parallel tools
- Temperature, top-p, token limits, stop sequences
- Provider-independent reasoning effort and token budgets
- Text, JSON object, and JSON Schema output formats
- Cache keys, streaming, cancellation
Retries And Errors
maxRetries controls Pi’s same-model retries. Provider failures, malformed output, invalid streams, and cancellation become RouterFrameworkError.
Cross-model fallback belongs to createRouter, not the runtime: enable it with the fallback option and it works with the Pi executor like any other. For fully managed retries and fallback chains, use Dari’s managed platform.
Per-API Option Gating
Some normalized options can’t be expressed on every provider API. Pi rejects those combinations up front asinvalid_request (HTTP 400) instead of surfacing a provider 5xx:
stopsequences onopenai-responses/azure-openai-responsestop_ponanthropic-messages- Forcing a specific tool with
tool_choiceongoogle-generative-ai/google-vertex response_format: json_objectonbedrock-converse-stream- Non-
autoimagedetailon APIs that can’t preserve it (details areauto,low, orhighand pass through on the OpenAI APIs)
json_object on anthropic-messages becomes a permissive JSON Schema (Anthropic has no native JSON-object mode), and metadata is never forwarded — only user, which maps to Anthropic’s metadata.user_id and nothing on other APIs.