npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cluski/pi-new-api

v0.1.0

Published

Pi extension: register a self-hosted New API gateway as a custom OpenAI-compatible provider.

Readme

pi-new-api

pi 开发的 New API 网关 extension:把自建的 New API 聚合网关注册成一个 OpenAI 兼容 provider,统一纳管公司买的多套 coding plan。

New API 把上游各家厂商(Zhipu GLM、Kimi/Moonshot、Anthropic、OpenAI、……)统一转译成 OpenAI /v1/chat/completions 协议吐出来,本 extension 就是在 pi 里挂上这个网关地址 + token,并把精选模型按各厂商官方参数配好。

安装

这是一个 npm pi 包(package.json 里带 pi manifest 和 pi-package 关键字)。有三种用法:

1) 本地开发 / 试跑(不发布) —— 直接用本地路径加载:

pi -e ./packages/new-api          # 临时加载(本次运行有效,不写入设置)
pi install ./packages/new-api     # 安装到用户设置(~/.pi/agent/settings.json)
pi install -l ./packages/new-api  # 安装到项目设置(.pi/settings.json,随仓库共享给团队)

2) 发布到 npm 后安装

npm publish --access public          # 先登录拥有 @cluski scope 的 npm 账号
pi install npm:@cluski/pi-new-api    # 别人/别的项目这样装

3) 从 git 安装(推到 GitHub 后):

pi install git:github.com/<user>/[email protected]

包里的 @earendil-works/*peerDependencies*),不打包进 tarball —— pi 运行时自带这些核心包,版本自动对齐。

配置

| 环境变量 | 必填 | 说明 | | --- | --- | --- | | NEW_API_KEY | ✅ | New API 后台签发的令牌(形如 sk-...)。extension 以 Authorization: Bearer <key> 发送。 | | NEW_API_BASE_URL | ❌ | 网关地址,默认 http://10.30.60.169:3000/v1。换机房/走域名时覆盖即可,无需改代码。 |

export NEW_API_KEY=sk-xxxxxxxxxxxxxxxx
# 可选:
export NEW_API_BASE_URL=http://your-newapi-host:3000/v1

想固化配置而不污染环境?把 apiKeybaseUrl 写进 ~/.pi/agent/models.jsonnew-api 段即可,pi 会按 models.json > extension > 内置 的优先级叠加。

暴露的模型

精选 5 个 coding 模型,compat 全部对齐 pi-ai 内置 provider 的官方定义,所以经网关走和直连厂商行为一致:

| model.id | 显示名 | 上游厂商 | 对齐的 pi-ai 内置定义 | 协议 | contextWindow | maxTokens | | --- | --- | --- | --- | --- | --- | --- | | glm-5.2 | GLM 5.2 | 智谱 Z.AI | zai-coding-cn glm-5.2 | openai-completions (thinkingFormat: zai) | 1,000,000 | 131,072 | | glm-4.7 | GLM 4.7 | 智谱 Z.AI | zai-coding-cn glm-4.7 | openai-completions (thinkingFormat: zai) | 204,800 | 131,072 | | k3 | Kimi K3 | Kimi/Moonshot | moonshotai kimi-k3 | openai-completions (thinkingFormat: openai, deferred tools) | 1,048,576 | 131,072 | | k3-256k | Kimi K3 256K | Kimi/Moonshot | 同 k3,仅缩短上下文窗口 | openai-completions | 262,144 | 131,072 | | kimi-for-coding | Kimi For Coding | Kimi/Moonshot | moonshotai kimi-k2.7-code | openai-completions (thinkingFormat: deepseek) | 262,144 | 262,144 |

⚠️ 注意 Kimi K3 系:pi-ai 官方的 kimi-coding provider 里 K3 走的是 Anthropic /v1/messages 协议(还带 User-Agent: KimiCLI/1.5、adaptive thinking)。但经 New API 网关后统一成了 OpenAI 协议,所以本 extension 按 moonshotai provider 的 kimi-k3(OpenAI 格式)来配,而非 kimi-coding(Anthropic 格式)。

用法

# 启动 pi 后切换模型
/model new-api/k3
# 或在启动时指定
pi --model new-api/glm-5.2

项目结构

new-api/
├── package.json   npm 包清单(name/version/keywords=pi-package/pi.extensions manifest/peerDependencies)
├── src/index.ts   扩展工厂:注册 new-api provider + 5 个模型
├── tsconfig.json
├── README.md
└── LICENSE

类型检查

npm install        # dev 依赖:typescript;pi 核心包通过 workspace 软链提供类型
npm run check      # tsc --noEmit

注意事项

  • 新增/改名模型:New API 后台改了渠道名,直接改 src/index.ts 里的 id 字段即可,无需动其它配置。
  • 换网关地址:覆盖 NEW_API_BASE_URL 环境变量,或改 src/index.ts 里的默认值。
  • 换 tokenexport NEW_API_KEY=... 即可,extension 不会缓存;想用命令式取 key 也可写 apiKey: "!pass-show newapi-token"