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

claude-code-router-tiantianai

v1.0.0

Published

TianTianAI customized Claude Code Router - Route Claude Code requests to TianTianAI API with intelligent model selection

Readme

Claude Code Router - TianTianAI 定制版

基于 claude-code-router 开发的定制版本,专门配置用于 TianTianAI 的 Claude API 服务。

✨ 特性

  • 智能路由: 根据任务类型自动选择最适合的模型(默认、后台、推理、长上下文)
  • TianTianAI 集成: 预配置 TianTianAI 的 Claude API 服务
  • 多模型支持: 支持 claude-opus-4 和 claude-sonnet-4 思维模型
  • 动态模型切换: 在 Claude Code 中使用 /model 命令动态切换模型
  • 成本优化: 根据任务复杂度智能选择模型以优化成本

🚀 快速开始

1. 环境要求

确保已安装 Node.js 16.0.0 或更高版本:

node --version

2. 安装依赖

npm install

3. 构建项目

npm run build

4. 配置 API 密钥

编辑配置文件 ~/.claude-code-router/config.json

{
  "Providers": [
    {
      "name": "tiantianai",
      "api_base_url": "https://tiantianai.pro/api/v1/chat/completions",
      "api_key": "your-actual-api-key-here",
      "models": [
        "claude-opus-4-20250514-thinking",
        "claude-sonnet-4-20250514-thinking"
      ]
    }
  ],
  "Router": {
    "default": "tiantianai,claude-sonnet-4-20250514-thinking",
    "background": "tiantianai,claude-sonnet-4-20250514-thinking",
    "think": "tiantianai,claude-opus-4-20250514-thinking",
    "longContext": "tiantianai,claude-opus-4-20250514-thinking"
  },
  "APIKEY": "your-access-key",
  "HOST": "127.0.0.1",
  "LOG": true
}

重要: 将 your-actual-api-key-here 替换为您从 TianTianAI 获得的实际 API 密钥。

5. 启动服务

node dist/cli.js start

服务将在 http://localhost:3456 启动。

6. 安装和配置 Claude Code

如果还没有安装 Claude Code:

npm install -g @anthropic-ai/claude-code

配置 Claude Code 使用本地代理:

export ANTHROPIC_BASE_URL="http://localhost:3456"
export ANTHROPIC_AUTH_TOKEN="your-access-key"

7. 测试运行

claude --print "Hello, this is a test message"

📋 配置说明

路由策略

  • default: 一般对话和简单任务使用 claude-sonnet-4-20250514-thinking
  • background: 后台任务使用成本更低的模型
  • think: 复杂推理任务使用 claude-opus-4-20250514-thinking
  • longContext: 长文本处理使用 claude-opus-4-20250514-thinking

智能路由触发条件

  • 长上下文: 当输入 token 超过 60,000 时自动切换到 longContext 模型
  • 推理模式: 检测到 thinking 参数时使用 think 模型
  • 后台任务: claude-3-5-haiku 模型请求自动路由到 background 模型

动态模型切换

在 Claude Code 中可以使用以下命令动态切换模型:

/model tiantianai,claude-opus-4-20250514-thinking

🛠️ 开发命令

  • npm run build: 构建项目
  • node dist/cli.js start: 启动服务
  • node dist/cli.js stop: 停止服务
  • node dist/cli.js status: 查看服务状态

📊 API 端点

  • POST /v1/messages: Anthropic Messages API (Claude Code 使用)
  • POST /v1/chat/completions: OpenAI 兼容的聊天 API
  • GET /v1/models: 获取可用模型列表

🔧 故障排除

1. 检查服务状态

node dist/cli.js status

2. 检查配置

cat ~/.claude-code-router/config.json

3. 查看日志

日志文件位于 ~/.claude-code-router/claude-code-router.log

4. 测试 API 连接

curl -H "Authorization: Bearer your-access-key" \
     -H "Content-Type: application/json" \
     -d '{"model":"claude-sonnet-4-20250514-thinking","messages":[{"role":"user","content":"Hello"}],"max_tokens":100}' \
     http://localhost:3456/v1/messages

📝 许可证

MIT License

🙏 致谢

本项目基于 claude-code-router 开发,感谢原作者的优秀工作。


TianTianAI Claude Code Router 团队