nim-rotator

Cloudflare Pages 多 key 轮换代理 · 转 NVIDIA NIM /v1/chat/completions


用法

export K="https://YOUR-PAGES-PROJ.pages.dev/v1"
curl -s $K/chat/completions \
  -H "Authorization: Bearer anything" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta/llama-3.3-70b-instruct",
    "messages": [{"role":"user","content":"hello"}]
  }'

Hermes config.yaml

providers:
  - name: nim_cf_pages
    type: openai
    base_url: "https://YOUR-PROJ.pages.dev/v1"
    api_key: "anything"
    models:
      - meta/llama-3.3-70b-instruct
default_provider: nim_cf_pages
default_model: meta/llama-3.3-70b-instruct

健康检查

curl https://YOUR-PROJ.pages.dev/health

部署

Pages 项目 root = 仓库根 · Functions 由 functions/ 目录自动发现 · 无需 wrangler · 无需 npm install

KV 配置

  1. Cloudflare Dashboard → Pages → 选项目 → Settings → Functions → KV namespace bindings
  2. 新建 namespace 名字 NIM_KEYS,绑到 Production
  3. 从 Dashboard 进 KV → 编辑值,写三行:
    key:1 → {"value":"nvapi-真实key1","cooldownUntil":0}
    key:2 → {"value":"nvapi-真实key2","cooldownUntil":0}
    key:3 → {"value":"nvapi-真实key3","cooldownUntil":0}

原理

每个请求 · Pages Function 拉 KV 里所有 key:* → 跳过冷却中的 → 随机选一条 → 透传 NVIDIA NIM

撞到 429/402 · 把这条 key 的 cooldownUntil 写到 KV 默认 5 分钟后恢复 · 期间这条 key 不会被选

限制


github: 521w/cloudflare-pages-nim-rotator