原始内容
@h00w/pi-provider-aihubmix
Pi provider extension that auto-registers AIHubMix models for the pi coding agent.
- Pulls the live model catalog from AIHubMix
- Registers chat/agent models under the
aihubmixprovider - Routes Claude → Anthropic Messages, Gemini → Google Generative AI, everything else → OpenAI Chat Completions
- Caches the catalog on disk and refreshes on demand
- Sends an
APP-Codeheader (defaults toDBPV7867) for developer discounts
AI services powered by AIHubMix.
Install
pi install npm:@h00w/pi-provider-aihubmix
Or for local development:
pi install ./path/to/pi-provider-aihubmix
# or one-shot
pi -e ./path/to/pi-provider-aihubmix
Setup
- Create an API key at console.aihubmix.com (
sk-...). - Provide the key in either way:
export AIHUBMIX_API_KEY=sk-...
or inside pi:
/login aihubmix
- Pick a model:
/model auto
/model aihubmix/gpt-5.6-sol
/model aihubmix/claude-sonnet-5
/model, the footer, and --list-models primarily show model ids. Use provider/id when you need to disambiguate.
Models only appear in
/modeland--list-modelsafter an API key is available (env var,/login aihubmix, or--api-key).If you install the package but have not configured a key yet,
/modelno longer errors withCould not refresh aihubmix— log in or export the env var to use models.Behind an HTTP proxy, this extension reads
HTTP(S)_PROXY/NO_PROXYfor catalog refresh. Alternatively setNODE_USE_ENV_PROXY=1so Node's global fetch uses the proxy.
What gets registered
By default the extension:
| Rule | Behavior |
|---|---|
| Type | Only llm / chat models from the catalog |
| Tools | Keeps models that advertise tools or function_calling |
| Auto router | Always includes auto (smart router) |
| Pure chat | Excluded when requireTools is true |
Protocol routing:
| Model | API | Base URL |
|---|---|---|
claude* |
anthropic-messages |
https://aihubmix.com |
cc-*, anthropic-* (configurable) |
anthropic-messages |
https://aihubmix.com |
gemini* / gemma* |
google-generative-ai |
https://aihubmix.com/gemini/v1beta |
| everything else | openai-completions |
https://aihubmix.com/v1 |
cc-* models are AIHubMix Claude Code endpoints and expect the Anthropic Messages wire format. Prefix routing is controlled by forceAnthropicPrefixes.
Configuration
Optional file: ~/.pi/agent/aihubmix.json
{
"apiKeyEnv": "AIHUBMIX_API_KEY",
"baseUrl": "https://aihubmix.com/v1",
"anthropicBaseUrl": "https://aihubmix.com",
"geminiBaseUrl": "https://aihubmix.com/gemini/v1beta",
"appCode": "DBPV7867",
"includeAuto": true,
"requireTools": true,
"allow": [],
"deny": [],
"protocols": {
"openai": true,
"anthropic": true,
"gemini": true
},
"forceAnthropicPrefixes": ["cc-", "anthropic-"],
"cacheTtlHours": 12
}
Fields
| Field | Default | Description |
|---|---|---|
apiKeyEnv |
AIHUBMIX_API_KEY |
Env var holding the API key |
baseUrl |
https://aihubmix.com/v1 |
OpenAI-compatible endpoint |
anthropicBaseUrl |
https://aihubmix.com |
Anthropic Messages endpoint |
geminiBaseUrl |
https://aihubmix.com/gemini/v1beta |
Gemini native endpoint (must include /v1beta for pi) |
appCode |
DBPV7867 |
Value for the APP-Code header. Set "" to disable |
includeAuto |
true |
Keep smart-router auto models |
requireTools |
true |
Drop models without tool/function calling |
allow |
[] |
Substring allowlist (empty = all) |
deny |
[] |
Substring denylist |
protocols.* |
all true |
Enable/disable wire protocols |
forceAnthropicPrefixes |
["cc-", "anthropic-"] |
Model id prefixes forced onto Anthropic Messages (startsWith, case-insensitive). Use [] to disable |
cacheTtlHours |
12 |
Disk cache lifetime |
APP-Code
Requests include:
APP-Code: DBPV7867
Override or disable in config:
{ "appCode": "your-code" }
{ "appCode": "" }
Commands
| Command | Description |
|---|---|
/aihubmix-refresh |
Force-refresh the model catalog (bypass cache) |
/aihubmix-status |
Show registered model count, source, and config summary |
Cache
Catalog cache file:
~/.pi/agent/aihubmix-models-cache.json
- Fresh cache is reused within
cacheTtlHours(including native/modelsoft refresh) - Network failures fall back to a stale cache when available
- Offline /
allowNetwork=falserefresh uses the disk cache only - Offline first-run falls back to a single
automodel - Catalog HTTP goes through
HTTP(S)_PROXYwhen set (see Setup note above)
Conflict with models.json
If ~/.pi/agent/models.json already defines providers.aihubmix, pi layers that file over this extension. You will see a warning on load. Prefer either:
- let this extension manage the catalog, or
- use
modelOverridesinmodels.jsonfor small tweaks
Development
npm install
npm test
npm run typecheck
# try locally
pi -e .
License
MIT