Skip to content

About

Pi model provider extension for OpenOrange instances

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

pi-openorange-provider

Pi extension that registers OpenOrange as a model provider, so /login can sign in to an OpenOrange Sunport and /model can pick any model that Sunport serves.

Install

pi install git:github.com/2bb-dev/pi-openorange-provider

Try it without installing:

pi -e git:github.com/2bb-dev/pi-openorange-provider

Sign in

/login  →  Sign in with an API key  →  OpenOrange

The flow asks for two things:

  1. Sunport address — the root URL of your OpenOrange Sunport, e.g. https://acme.openorange.ai. Prefilled from OPENORANGE_BASE_URL. Only public HTTPS hosts are accepted; loopback/plain HTTP is rejected.
  2. Inference key — the sk-... key issued in the OpenOrange console under API keys.

Login verifies the key against the Sunport and stores it in ~/.pi/agent/auth.json. /login openorange jumps straight to it.

Headless/CI use needs no login:

export OPENORANGE_BASE_URL=https://acme.openorange.ai
export OPENORANGE_API_KEY=sk-...

What it does

Model catalog. The model list is fetched from the Sunport (GET /v1/model/info, limited to the models GET /v1/models lists) with your key, so you see exactly the models that key may use (on a free trial, only the models the trial includes), with the Sunport's own context windows, pricing, and capabilities. Deployments that are not chat models (embeddings, speech, images, video) and per-subscription slot aliases (openai/gpt-5.5/2) are hidden.

Routing. Each deployment declares its Pi protocol in model_info.pi_api (the same contract OpenOrange Code uses): openai-responses models go to POST /v1/responses so reasoning summaries and encrypted reasoning replay work, anthropic/* models go to the Sunport's Anthropic surface (POST /v1/messages) for native prompt caching and thinking, and everything else uses POST /v1/chat/completions. Without pi_api, mode: responses selects the Responses surface and Claude aliases the Anthropic one.

Capabilities. Deployments proxied through the OpenOrange upstream carry no LiteLLM supports_* flags, so thinking and vision come from the Sunport's Pi metadata: pi_reasoning, pi_thinking_level_map, and pi_compat (for example forceAdaptiveThinking, which Claude Sonnet 5 / Opus 4.8+ / Fable 5 / Haiku 5.5 need and is applied by default for them). Image input is enabled unless the Sunport sets supports_vision: false; Pi drops images for text-only models before the request is sent.

Spend attribution. Requests carry the LiteLLM user the inference key belongs to (user for OpenAI, metadata.user_id for Anthropic), read from GET /key/info at login, so OpenOrange spend reports attribute Pi traffic to that user.

Prompt caching. On the Anthropic surface Pi already emits cache_control blocks. On the OpenAI surface Pi only sends prompt_cache_key when the base URL is api.openai.com, so requests to an OpenOrange Sunport carried no cache affinity at all; this extension adds it, keyed by the Pi session id. It is skipped when the caller disables caching or already set a key.

Measured on gpt-5.6-* (ChatGPT-subscription route, 14.8k-token prefix): cache hits do occur but are backend-controlled and unreliable — 0–25% on a cold prefix, 60–85% once the prefix is hot — and prompt_cache_key did not move those numbers on that route. The parameter is still correct to send (the OpenOrange LiteLLM fork forwards it to the Codex backend as a session_id header); the remaining loss is upstream of Pi, in the Sunport's proxy chain.

Development

.npmrc sets omit=dev so installing this package into Pi does not pull the test toolchain. Ask for dev dependencies explicitly:

npm install --include=dev
npm test
npm run typecheck

test/live.test.ts runs against a real Sunport and is skipped unless credentials are present. It costs real tokens (~15k input per request):

OPENORANGE_BASE_URL=https://acme.openorange.ai OPENORANGE_API_KEY=sk-... \
  OPENORANGE_LIVE_MODEL=openai/gpt-5.6-luna npx vitest run test/live.test.ts
Path Purpose
extensions/openorange.ts Pi entry point; registers the provider
src/provider.ts Provider: login, auth resolution, model refresh, streaming
src/litellm.ts LiteLLM client and catalog → Pi model mapping (pi_* metadata)
src/payload.ts Cache-affinity and spend-attribution payload fields
src/config.ts Sunport address rules and endpoint layout

About

Pi model provider extension for OpenOrange instances

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages