apigather-act
v1.0.1
Published
Apigather API Activator for Claude Code & Codex (configurable verify URL)
Maintainers
Readme
apigather-activator
一个命令行激活器(bin:apigather),功能与 yunyi-activator 类似:验证 API Key 后,根据接口返回的 service_type 自动为 Claude Code 或 Codex CLI 写入本地配置。
本版本的特点:验证请求地址(verify URL)可配置。
激活器逻辑(做了什么)
整体流程:
- 交互式输入
API Key(密码输入,不回显)。 - 验证
API Key:向verifyUrl发起GET请求,带Authorization: Bearer <API Key>,要求返回 JSON。 - 解析返回的
service_type:claude:激活 Claude Codecodex:激活 Codex CLI
- 展示 Key 状态/配额/有效期等信息后二次确认。
- 写入本地配置并提示重启工具生效。
Claude Code(service_type = "claude")
通过定位 Claude Code 的 @anthropic-ai/claude-code/cli.js,在文件开头(跳过 shebang/注释/空行后)注入一段环境变量设置:
// APIGATHER_INJECTED_START
process.env.ANTHROPIC_BASE_URL="<baseUrl>/claude";
process.env.ANTHROPIC_AUTH_TOKEN="<API Key>";
// APIGATHER_INJECTED_END如果之前已经注入过,会先移除旧的 APIGATHER_INJECTED_START ~ APIGATHER_INJECTED_END 区块再写入,避免重复。
Codex CLI(service_type = "codex")
写入/更新 Codex 配置目录 ~/.codex/:
~/.codex/config.toml:设置model_provider = "apigather"并写入[model_providers.apigather](base_url="<baseUrl>/codex"、wire_api="responses"、temp_env_key="APIGATHER_API_KEY"、model="gpt-5-codex"等)。~/.codex/auth.json:写入OPENAI_API_KEY与APIGATHER_API_KEY(值均为该API Key)。
同样会清理旧的同名段落/标题与旧 model_provider 行,避免重复配置。
安装/运行
在本目录执行:
npm install
npm run build
node dist/index.js --help或安装为全局命令(示例):
npm install -g .
apigather --help
# 或
apigather-activator --help必要参数:verify URL(可配置)
验证地址用于校验 API Key,会发起:
GET <verify-url>- Header:
Authorization: Bearer <API Key>
配置方式(推荐配置文件,之后无需每次输入参数):
- 命令行:
--verify-url https://example.com/user/api/v1/me - 构建配置:编辑
apigather.config.json并重新执行npm run build(若已全局安装过,需要重新npm install -g .)
apigather.config.json 示例:
{
"verifyUrl": "https://example.com/user/api/v1/me",
"baseUrl": "https://example.com"
}中转 base URL(可选)
默认会从 verify-url 的 origin 推导中转地址:
- Claude:
<origin>/claude - Codex:
<origin>/codex
如需覆盖,可设置:
- 命令行:
--base-url https://example.com - 构建配置:
apigather.config.json中设置baseUrl
参数优先级
运行时参数优先于构建默认值:
- 命令行
--verify-url/--base-url - 构建配置
apigather.config.json(需要重新npm run build才会反映到dist/index.js)
发布到 npm(维护者)
- 已配置
prepublishOnly:执行npm publish前会自动npm run build,确保dist/为编译产物。 repository/homepage/bugs等字段需要你在仓库设置好远程地址后补齐(当前本仓库未配置git remote origin)。
