Skip to content

获取并管理 API 密钥 ​

浙中TOKEN运营中心-模型广场 用 API 密钥(也叫令牌 / Token / Key)来鉴权。一个账户可以创建多把密钥,分别用于不同的人、应用或环境,并独立控制额度与权限。

创建 API 密钥 ​

进入 API 密钥页

登录控制台 → 左侧 API 密钥 → 右上角 创建 API 密钥。

填写密钥信息
字段说明
名称便于识别,如 cherry-studio、prod-backend
额度该密钥可消耗的上限;可设为「无限制」
过期时间到期自动失效;可设为「永不过期」
分组从运营方预设的分组中选择,决定本密钥可用的模型范围与价格(见下)
模型限制可选,白名单限定此密钥仅能调用指定模型
IP 限制可选,限定调用来源 IP
复制密钥

创建后复制形如 sk-xxxxxxxxxxxxxxxx 的字符串。它只完整显示一次,请妥善保存。

WARNING

API 密钥等同于密码。不要硬编码进前端代码或提交到 Git 仓库;推荐通过环境变量注入。一旦泄露,立即在控制台删除并重建。

分组(Group) ​

分组决定一把密钥能用哪些模型、按什么价格计费。

  • 分组由运营方在后台预先配置(关联了哪些上游渠道、什么价格);你创建密钥时只需从可选分组里选择一个,无需自己配置渠道或倍率。
  • 例如:default 分组走标准线路,vip 分组可能走更高优先级或更低延迟的线路。
  • 调用时,请求会在密钥所属分组内自动选择可用线路(智能路由),背后机制见 基础概念。

在工具 / 代码中使用 ​

所有场景都是同一把 Key + 同一个 Base URL:

bash
export TOKEN_API_KEY="sk-xxxxxxxx"
export NOVAFARE_BASE_URL="https://ai.jhdataops.com/v1"
python
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["TOKEN_API_KEY"],
    base_url=os.environ["NOVAFARE_BASE_URL"],
)
text
API 地址:https://ai.jhdataops.com/v1
密钥:    sk-xxxxxxxx

查询余额与用量 ​

  • 控制台:在「数据看板」查看消耗、调用次数、各模型用量。
  • 接口:部分部署兼容 OpenAI 风格的用量查询端点 GET /v1/dashboard/billing/subscription 与 /v1/dashboard/billing/usage,可供第三方额度面板对接(是否开放以你的部署为准)。

TIP

建议为每个应用 / 每个人单独建一把密钥,便于按维度统计用量、出问题时精准吊销,互不影响。

按密钥查询每日消耗 ​

需要自建用量看板或按天对账时,每把密钥都能拉取指定区间内、逐日的消耗明细(金额 + Token 数),且只统计这把密钥自己的用量。

  • 端点:GET /api/usage/token/cost
  • 鉴权:用密钥自身,请求头 Authorization: Bearer sk-xxxx(额度用尽也能查)。
查询参数说明
start_date可选,起始日期 YYYY-MM-DD
end_date可选,结束日期 YYYY-MM-DD

TIP

默认返回近 7 天(含当日);自定义区间最长 7 天,且起始日期不得早于 30 天前。

bash
curl "https://ai.jhdataops.com/api/usage/token/cost" \
  -H "Authorization: Bearer sk-xxxxxxxx"
bash
curl "https://ai.jhdataops.com/api/usage/token/cost?start_date=2026-06-15&end_date=2026-06-17" \
  -H "Authorization: Bearer sk-xxxxxxxx"
bash
curl "https://ai.jhdataops.com/api/usage/token/cost?start_date=2026-06-17&end_date=2026-06-17" \
  -H "Authorization: Bearer sk-xxxxxxxx"
json
{
  "data": {
    "currency": "CNY",
    "end_date": "2026-06-12",
    "object": "token_cost_timeline",
    "periods": [
      {
        "date": "2026-06-10",
        "cost": 2757.765346,
        "request_count": 607,
        "tokens": {
          "input": 11656930,
          "output": 643933,
          "cache": 295388476,
          "total": 307689339
        }
      },
      {
        "date": "2026-06-11",
        "cost": 172.552268,
        "request_count": 144,
        "tokens": {
          "input": 1055,
          "output": 67581,
          "cache": 25763660,
          "total": 25832296
        }
      },
      {
        "date": "2026-06-12",
        "cost": 402.156538,
        "request_count": 193,
        "tokens": {
          "input": 6648,
          "output": 235862,
          "cache": 52913437,
          "total": 53155947
        }
      }
    ],
    "start_date": "2026-06-10",
    "summary": {
      "cost": 3332.474152,
      "request_count": 944,
      "tokens": {
        "input": 11664633,
        "output": 947376,
        "cache": 374065573,
        "total": 386677582
      }
    },
    "token_name": "某业务部门-测试用户"
  },
  "message": "",
  "success": true
}
json
{
    "message": "查询区间不能超过 7 天",
    "success": false
}

为什么和数据看板的金额对不上? ​

两者计费口径一致,差异来自时间窗口边界不同,并非计费错误。

本接口数据看板
起始边界start_date 当天 00:00:00请求时刻往前推 N 天(如 06-10 15:35)
结束边界end_date 当天 23:59:59请求时刻(如 06-17 15:35)
当日数据实时累计含截至请求时刻的当日数据

按账号查询全部密钥的每日消耗 ​

如果你名下有多把密钥,想一次性看清整个账号的消耗、各把密钥的横向对比、查询每个模型的消耗情况,使用这个账号级接口。

  • 端点:GET /api/usage/user/cost
  • 鉴权:用访问令牌(Access Token),请求头 Authorization: <access_token>。

WARNING

这里用的不是请求密钥。 此接口代表“你这个账号”,因此鉴权用的是访问令牌,而不是上面那种 sk-xxx 请求密钥:

  • 访问令牌在 控制台 → 个人资料 → 安全 → 访问令牌 里生成并复制,代表账号身份,能看到名下所有密钥的用量。
  • 请求头里直接填访问令牌本身即可(加不加 Bearer 前缀都能识别,推荐直接填裸令牌)。
查询参数说明
start_date可选,起始日期 YYYY-MM-DD
end_date可选,结束日期 YYYY-MM-DD
detail可选,传 true 时显示各模型的消耗明细

TIP

区间规则与“按密钥查询”一致:默认返回近 7 天(含当日);自定义区间最长 7 天,且起始日期不得早于 30 天前。

响应中会按密钥消耗从高到低排序;开启 detail 时,每把密钥下的模型同样按消耗倒序。

bash
curl "https://ai.jhdataops.com/api/usage/user/cost?start_date=2026-06-10&end_date=2026-06-16" \
  -H "Authorization: <access_token>"
bash
curl "https://ai.jhdataops.com/api/usage/user/cost?start_date=2026-06-10&end_date=2026-06-16&detail=true" \
  -H "Authorization: <access_token>"
json
{
  "data": {
    "currency": "CNY",
    "detail": true,
    "end_date": "2026-06-12",
    "keys": [
      {
        "models": [
          {
            "model_name": "claude-opus-4-7",
            "periods": [
              {
                "date": "2026-06-10",
                "quota": 186982472,
                "cost": 2617.754608,
                "request_count": 512,
                "tokens": {
                  "input": 10234567,
                  "output": 512345,
                  "cache": 280123456,
                  "cache_read": 252345678,
                  "cache_write": 27777778,
                  "total": 291370368
                }
              },
              {
                "date": "2026-06-11",
                "quota": 11234567,
                "cost": 157.283496,
                "request_count": 128,
                "tokens": {
                  "input": 1234,
                  "output": 56789,
                  "cache": 23456789,
                  "cache_read": 21234567,
                  "cache_write": 2222222,
                  "total": 23514812
                }
              },
              {
                "date": "2026-06-12",
                "quota": 27654321,
                "cost": 387.160494,
                "request_count": 176,
                "tokens": {
                  "input": 4567,
                  "output": 214567,
                  "cache": 50123456,
                  "cache_read": 46234567,
                  "cache_write": 3888889,
                  "total": 50342590
                }
              }
            ],
            "summary": {
              "quota": 225871360,
              "cost": 3162.198598,
              "request_count": 816,
              "tokens": {
                "input": 10240368,
                "output": 783701,
                "cache": 353703701,
                "cache_read": 319814812,
                "cache_write": 33888889,
                "total": 365227770
              }
            }
          },
          {
            "model_name": "claude-haiku-4-5-20251001",
            "periods": [
              {
                "date": "2026-06-10",
                "quota": 712,
                "cost": 0.009968,
                "request_count": 2,
                "tokens": {
                  "input": 1234,
                  "output": 28,
                  "cache": 0,
                  "cache_read": 0,
                  "cache_write": 0,
                  "total": 1262
                }
              },
              {
                "date": "2026-06-11",
                "quota": 256,
                "cost": 0.003584,
                "request_count": 1,
                "tokens": {
                  "input": 432,
                  "output": 16,
                  "cache": 0,
                  "cache_read": 0,
                  "cache_write": 0,
                  "total": 448
                }
              },
              {
                "date": "2026-06-12",
                "quota": 345,
                "cost": 0.004830,
                "request_count": 1,
                "tokens": {
                  "input": 612,
                  "output": 15,
                  "cache": 0,
                  "cache_read": 0,
                  "cache_write": 0,
                  "total": 627
                }
              }
            ],
            "summary": {
              "quota": 1313,
              "cost": 0.018382,
              "request_count": 4,
              "tokens": {
                "input": 2278,
                "output": 59,
                "cache": 0,
                "cache_read": 0,
                "cache_write": 0,
                "total": 2337
              }
            }
          }
        ],
        "periods": [
          {
            "date": "2026-06-10",
            "quota": 186983184,
            "cost": 2617.764576,
            "request_count": 514,
            "tokens": {
              "input": 10235801,
              "output": 512373,
              "cache": 280123456,
              "cache_read": 252345678,
              "cache_write": 27777778,
              "total": 291371630
            }
          },
          {
            "date": "2026-06-11",
            "quota": 11234823,
            "cost": 157.287080,
            "request_count": 129,
            "tokens": {
              "input": 1666,
              "output": 56805,
              "cache": 23456789,
              "cache_read": 21234567,
              "cache_write": 2222222,
              "total": 23515260
            }
          },
          {
            "date": "2026-06-12",
            "quota": 27654666,
            "cost": 387.165324,
            "request_count": 177,
            "tokens": {
              "input": 5179,
              "output": 214582,
              "cache": 50123456,
              "cache_read": 46234567,
              "cache_write": 3888889,
              "total": 50343217
            }
          }
        ],
        "summary": {
          "quota": 225872673,
          "cost": 3162.216980,
          "request_count": 820,
          "tokens": {
            "input": 10242646,
            "output": 783760,
            "cache": 353703701,
            "cache_read": 319814812,
            "cache_write": 33888889,
            "total": 365230107
          }
        },
        "token_id": 1001,
        "token_name": "技术研发部-张三"
      },
      {
        "models": [
          {
            "model_name": "claude-sonnet-4-6",
            "periods": [
              {
                "date": "2026-06-10",
                "quota": 107234567,
                "cost": 1501.283938,
                "request_count": 1234,
                "tokens": {
                  "input": 2987654,
                  "output": 698765,
                  "cache": 189234567,
                  "cache_read": 145678901,
                  "cache_write": 43555666,
                  "total": 192920986
                }
              },
              {
                "date": "2026-06-11",
                "quota": 24567890,
                "cost": 343.950460,
                "request_count": 312,
                "tokens": {
                  "input": 56789,
                  "output": 143210,
                  "cache": 45678901,
                  "cache_read": 35678901,
                  "cache_write": 10000000,
                  "total": 45878900
                }
              },
              {
                "date": "2026-06-12",
                "quota": 10987654,
                "cost": 153.827156,
                "request_count": 267,
                "tokens": {
                  "input": 176543,
                  "output": 123456,
                  "cache": 24567890,
                  "cache_read": 20987654,
                  "cache_write": 3580236,
                  "total": 24867889
                }
              }
            ],
            "summary": {
              "quota": 142790111,
              "cost": 1999.061554,
              "request_count": 1813,
              "tokens": {
                "input": 3220986,
                "output": 965431,
                "cache": 259481358,
                "cache_read": 202345456,
                "cache_write": 57135902,
                "total": 263667775
              }
            }
          },
          {
            "model_name": "claude-haiku-4-5-20251001",
            "periods": [
              {
                "date": "2026-06-10",
                "quota": 0,
                "cost": 0,
                "request_count": 0,
                "tokens": {
                  "input": 0,
                  "output": 0,
                  "cache": 0,
                  "cache_read": 0,
                  "cache_write": 0,
                  "total": 0
                }
              },
              {
                "date": "2026-06-11",
                "quota": 0,
                "cost": 0,
                "request_count": 0,
                "tokens": {
                  "input": 0,
                  "output": 0,
                  "cache": 0,
                  "cache_read": 0,
                  "cache_write": 0,
                  "total": 0
                }
              },
              {
                "date": "2026-06-12",
                "quota": 756,
                "cost": 0.010584,
                "request_count": 2,
                "tokens": {
                  "input": 1356,
                  "output": 30,
                  "cache": 0,
                  "cache_read": 0,
                  "cache_write": 0,
                  "total": 1386
                }
              }
            ],
            "summary": {
              "quota": 756,
              "cost": 0.010584,
              "request_count": 2,
              "tokens": {
                "input": 1356,
                "output": 30,
                "cache": 0,
                "cache_read": 0,
                "cache_write": 0,
                "total": 1386
              }
            }
          }
        ],
        "periods": [
          {
            "date": "2026-06-10",
            "quota": 107234567,
            "cost": 1501.283938,
            "request_count": 1234,
            "tokens": {
              "input": 2987654,
              "output": 698765,
              "cache": 189234567,
              "cache_read": 145678901,
              "cache_write": 43555666,
              "total": 192920986
            }
          },
          {
            "date": "2026-06-11",
            "quota": 24567890,
            "cost": 343.950460,
            "request_count": 312,
            "tokens": {
              "input": 56789,
              "output": 143210,
              "cache": 45678901,
              "cache_read": 35678901,
              "cache_write": 10000000,
              "total": 45878900
            }
          },
          {
            "date": "2026-06-12",
            "quota": 10988410,
            "cost": 153.837740,
            "request_count": 269,
            "tokens": {
              "input": 177899,
              "output": 123486,
              "cache": 24567890,
              "cache_read": 20987654,
              "cache_write": 3580236,
              "total": 24869275
            }
          }
        ],
        "summary": {
          "quota": 142790867,
          "cost": 1999.072138,
          "request_count": 1815,
          "tokens": {
            "input": 3222342,
            "output": 965461,
            "cache": 259481358,
            "cache_read": 202345456,
            "cache_write": 57135902,
            "total": 263669161
          }
        },
        "token_id": 1002,
        "token_name": "业务运营部-李四"
      }
    ],
    "object": "user_keys_cost_timeline",
    "periods": [
      {
        "date": "2026-06-10",
        "quota": 294217751,
        "cost": 4119.048514,
        "request_count": 1748,
        "tokens": {
          "input": 13223455,
          "output": 1211138,
          "cache": 469358023,
          "cache_read": 398024579,
          "cache_write": 71333444,
          "total": 484292616
        }
      },
      {
        "date": "2026-06-11",
        "quota": 35802713,
        "cost": 501.237540,
        "request_count": 441,
        "tokens": {
          "input": 58455,
          "output": 200015,
          "cache": 69135690,
          "cache_read": 56913468,
          "cache_write": 12222222,
          "total": 69394160
        }
      },
      {
        "date": "2026-06-12",
        "quota": 38643076,
        "cost": 541.003064,
        "request_count": 446,
        "tokens": {
          "input": 183078,
          "output": 338068,
          "cache": 74691346,
          "cache_read": 67222221,
          "cache_write": 7469125,
          "total": 75212492
        }
      }
    ],
    "start_date": "2026-06-10",
    "summary": {
      "quota": 368663540,
      "cost": 5161.289118,
      "request_count": 2635,
      "tokens": {
        "input": 13464988,
        "output": 1749221,
        "cache": 613185059,
        "cache_read": 522160268,
        "cache_write": 91024791,
        "total": 628899268
      }
    },
    "username": "demo_account"
  },
  "message": "",
  "success": true
}
json
{
    "message": "查询区间不能超过 7 天",
    "success": false
}

响应结构 ​

字段所在层级说明
object顶层固定为 user_keys_cost_timeline
username顶层账号用户名
currency顶层币种(如 CNY)
detail顶层是否返回了模型明细
start_date / end_date顶层实际生效的查询区间
summary顶层账号全部密钥合计的区间汇总
periods[]顶层账号合计的逐日明细,每天一条(无消耗的天补零)
keys[]顶层逐把密钥的数据,按消耗倒序
token_id / token_namekeys[]密钥 ID 与名称
summary / periods[]keys[]该密钥的汇总与逐日明细,结构同账号级
models[]keys[]仅 detail=true 时返回,密钥下每个模型各自的 summary / periods
quotasummary / period原始未折算额度
costsummary / period按站点展示口径折算后的金额(配合顶层 currency)
request_countsummary / period请求次数
tokenssummary / periodToken 用量明细,见下表
partialperiod仅当区间含当日时,当日那条会带 "partial": true

tokens 各字段:

字段说明
input输入 Token
output输出 Token
cache_read读缓存命中
cache_write写缓存
cache读 + 写合计 = cache_read + cache_write(兼容旧字段)
totalinput + output + cache

浙中TOKEN运营中心-模型广场 · 一个 API Key 接入全量大模型