自定义 Provider
扩展可以通过 pi.registerProvider() 注册自定义模型 Provider。
可以实现
- 代理 — 通过公司代理或 API 网关路由请求
- 自定义端点 — 使用自托管或私有模型部署
- OAuth/SSO — 为企业 Provider 添加认证流程
- 自定义 API — 为非标准 LLM API 实现流式支持
快速参考
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
export default function (pi: ExtensionAPI) {
// 覆盖现有 Provider 的 baseUrl
pi.registerProvider("anthropic", {
baseUrl: "https://proxy.example.com"
});
// 注册新 Provider 及模型
pi.registerProvider("my-provider", {
baseUrl: "https://api.example.com",
apiKey: "MY_API_KEY",
api: "openai-completions",
models: [
{
id: "my-model",
name: "我的模型",
reasoning: false,
input: ["text", "image"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 128000,
maxTokens: 4096
}
]
});
}