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

ai-agent-router

v0.1.12

Published

A unified API gateway for managing multiple AI model providers (Anthropic, OpenAI, Gemini, etc.)

Readme

AI Agent Router

一个统一的 API 网关,用于管理多个 AI 模型供应商(Anthropic、OpenAI、Gemini 等),为 Claude、Zcode、Alma 等客户端软件提供统一的接口。

功能特性

  • ✅ 支持多种 AI 模型协议(OpenAI、Anthropic、Gemini)
  • ✅ 独立 Gateway 服务架构,可与 Web UI 分离运行
  • ✅ Web 管理界面,可视化配置和管理
  • ✅ 模型供应商管理(添加、编辑、删除)
  • ✅ 模型管理(手动添加、自动拉取模型列表)
  • ✅ 请求日志记录和查看(支持流式响应的美化展示)
  • ✅ 双端点支持(/v1/*/api/gateway/*
  • ✅ API Key 认证保护 Gateway 服务
  • ✅ CLI 工具,易于安装和使用
  • ✅ SQLite 数据库,轻量级存储

安装

npm install -g ai-agent-router

使用方法

启动完整服务(Web UI + Gateway)

aar start

默认在 http://localhost:9527 启动 Web 管理界面,Gateway 服务运行在 http://localhost:1357

仅启动 Gateway 服务

aar gateway

仅启动独立的 API 网关服务,默认在 http://localhost:1357

配置选项

# 指定 Web UI 端口
aar start --port 8080

# 指定主机名
aar start --hostname 0.0.0.0

# 指定 Gateway 端口
aar gateway --port 3000

配置管理

# 获取配置
aar config --get port

# 设置配置
aar config --set port 8080

# 设置 Gateway API Key(用于外部客户端认证)
aar config --set api_key "your-secret-key"

Web 管理界面

启动后访问 http://localhost:9527,你可以:

  1. 配置网关:设置端口、API Key 等
  2. 管理供应商:添加、编辑、删除模型供应商
  3. 管理模型:手动添加模型或一键拉取模型列表
  4. 查看日志:查看所有 API 请求日志,包括流式响应的美化显示
  5. 服务管理:独立启动/停止 Gateway 服务,不影响 Web UI

添加供应商

  1. 访问 Web 界面,进入"供应商"页面
  2. 点击"添加供应商"
  3. 填写信息:
    • 名称:供应商名称(如 "OpenAI")
    • 协议:选择协议类型(OpenAI、Anthropic、Gemini)
    • Base URL:API 基础 URL(如 https://api.openai.com/v1
    • API Key:供应商的 API Key

添加模型

手动添加

  1. 进入"模型"页面
  2. 点击"手动添加"
  3. 选择供应商,填写模型名称和模型 ID

自动拉取

  1. 进入"模型"页面
  2. 在"一键拉取模型列表"区域,点击对应供应商的"拉取模型"按钮
  3. 系统会自动从供应商 API 拉取可用模型列表

使用网关

配置好供应商和模型后,客户端可以通过以下方式使用:

Gateway 端点(推荐 - 独立服务)

Gateway 服务运行在 http://localhost:1357,支持两种兼容的端点:

OpenAI 兼容接口

POST http://localhost:1357/v1/chat/completions
Content-Type: application/json
x-api-key: your-gateway-api-key

{
  "model": "gpt-4",
  "messages": [...],
  "stream": true  // 支持流式响应
}

Gateway 专用接口

POST http://localhost:1357/api/gateway/v1/chat/completions
Content-Type: application/json
x-api-key: your-gateway-api-key

{
  "model": "gpt-4",
  "messages": [...],
  "stream": true  // 支持流式响应
}

模型列表

GET http://localhost:1357/v1/models
GET http://localhost:1357/api/gateway/models

Anthropic 兼容接口

POST http://localhost:1357/api/gateway/v1/messages
Content-Type: application/json
x-api-key: your-gateway-api-key

{
  "model": "claude-3-5-sonnet-20241022",
  "messages": [...]
}

认证说明

  • 如果配置了 Gateway API Key,客户端需要在请求头中提供:x-api-key: your-gateway-api-key
  • 支持 Bearer token 格式:Authorization: Bearer your-gateway-api-key

开发

本地开发

# 安装依赖
npm install

# 开发模式
npm run dev

# 构建
npm run build

# 启动生产模式
npm start

项目结构

aar/
├── src/
│   ├── server/              # 网关服务器
│   │   ├── gateway.ts       # 核心网关逻辑
│   │   ├── gateway-server.ts # 独立 Gateway 服务器
│   │   ├── service-manager.ts # 服务管理器
│   │   ├── providers/       # 协议适配器
│   │   └── logger.ts       # 请求日志记录
│   ├── db/                  # 数据库层
│   │   ├── database.ts       # 数据库连接
│   │   ├── schema.ts         # SQLite 表结构
│   │   └── queries.ts        # 数据库查询
│   ├── app/                 # Next.js 应用
│   │   ├── api/             # API 路由
│   │   │   ├── gateway/     # Gateway 代理端点
│   │   │   └── service/     # 服务管理端点
│   │   └── (pages)/        # 前端页面
│   └── cli/                 # CLI 入口
│       ├── index.ts         # 主 CLI 程序
│       └── gateway-server.ts # Gateway CLI 入口
├── package.json
└── README.md

技术栈

  • Next.js 14 - 全栈框架
  • TypeScript - 类型安全
  • Tailwind CSS - 样式框架
  • SQLite3 - 数据库
  • Commander.js - CLI 框架

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request!