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

pi-provider-headers

v0.1.1

Published

Pi extension package that injects provider-specific default headers based on each provider API type.

Readme

pi-provider-headers

pi-provider-headers 是一个 Pi extension package。

它会按 models.json 中每个 provider 的 api 类型,自动注入默认 headers,模拟 codex CLI / claude code CLI 的请求特征。新增自定义 provider 时,不需要再手动为每个 provider 重复配置 headers。

工作原理

启动时读取 ~/.pi/agent/models.json~/.pi/agent/provider-headers.json,对每个 provider:

  1. 取其 api 类型(provider 级优先,否则取第一个 model 级)。
  2. 在配置 rules 中匹配 api,渲染 header 值(支持 {var} 模板)。
  3. models.json 里已有的 headers 合并(models.json 同名 header 优先)。
  4. 调用 pi.registerProvider(name, { baseUrl, apiKey, authHeader, headers }) 注入,并透传原有鉴权字段。

配置文件

~/.pi/agent/provider-headers.json 缺失时,会使用扩展内置默认配置:

{
  "debug": false,  // 是否开启调试日志,默认 false
  "vars": { "codexVersion": "0.141.0", "claudeCodeVersion": "2.1.178" },
  "rules": [
    {
      "name": "codex-cli",
      "api": ["openai-responses", "openai-codex-responses", "azure-openai-responses", "openai-completions"],
      "headers": {
        "User-Agent": "codex_cli_rs/{codexVersion}  ({osInfo}) Terminal",
        "originator": "codex_cli_rs",
        "version": "{codexVersion}"
      }
    },
    {
      "name": "claude-code",
      "api": ["anthropic-messages"],
      "headers": {
        "User-Agent": "{claudeCodeVersion} (Claude Code)",
        "anthropic-version": "2023-06-01",
        "anthropic-beta": "context-1m-2025-08-07"
      }
    }
  ]
}

安装

本地路径安装

pi install /absolute/path/to/pi-provider-headers

npm 安装

正式发布到 npm 后可用:

pi install npm:pi-provider-headers

临时试用

pi -e ./pi-provider-headers

使用

安装后重新启动 Pi,或执行:

/reload

启动后如果配置了 debug: true,会打印类似日志:

[provider-headers] 已注入 headers:

如果有 provider 未命中规则,也会打印跳过列表。默认不打印日志,需要调试时请在配置文件中设置 debug: true

生效与调试

  • 若想让自动检测的 osInfo 真正生效,请删除 models.json 中各 provider 已手写的同名 headers
  • 这个包当前通过 package.json 里的 pi.extensions 暴露入口:./index.ts
  • 修改代码后可用 /reload 热重载

开发

发布前检查:

npm run check:import
npm run pack:check
npm run prepublishOnly

更完整的首次发布步骤见:

  • .docs/first-npm-release.md

作用范围

仅处理 ~/.pi/agent/models.json 中显式声明的 provider。项目级 .pi/models.json 不处理。