模型倍率同步模組
功能說明
介面字首統一為 http(s)://<your-domain>
生產環境應使用 HTTPS 以保證認證令牌。 HTTP 僅建議用於開發環境。
專門用於模型定價同步的高階功能 。支援從多個上游源併發獲取倍率配置,自動識別不同介面格式,提供資料可信度評估。主要用於批次更新模型定價資訊。
🔐 Root鑑權
獲取可同步渠道列表
- 介面名稱:獲取可同步渠道列表
- HTTP 方法:GET
- 路徑:
/api/ratio_sync/channels - 鑑權要求:Root
- 功能簡介:獲取系統中所有可用於倍率同步的渠道列表,包括有效 BaseURL 的渠道和官方預設
💡 請求示例:
const response = await fetch('/api/ratio_sync/channels', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_root_token',
'New-Api-User': 'your_user_id'
}
});
const data = await response.json();✅ 成功響應示例:
{
"success": true,
"message": "",
"data": [
{
"id": 1,
"name": "OpenAI官方",
"base_url": "https://api.openai.com",
"status": 1
},
{
"id": 2,
"name": "Claude API",
"base_url": "https://api.anthropic.com",
"status": 1
},
{
"id": -100,
"name": "官方倍率預設",
"base_url": "https://basellm.github.io",
"status": 1
}
]
}❗ 失敗響應示例:
{
"success": false,
"message": "獲取渠道列表失敗"
}🧾 欄位說明:
data(陣列): 可同步渠道列表id(數字): 渠道 ID,-100 為官方預設name(字串): 渠道名稱base_url(字串): 渠道基礎 URLstatus(數字): 渠道狀態,1=啟用
從上游拉取倍率
- 介面名稱:從上游拉取倍率
- HTTP 方法:POST
- 路徑:
/api/ratio_sync/fetch - 鑑權要求:Root
- 功能簡介:從指定的上游渠道或自定義 URL 拉取模型倍率配置,支援併發獲取和差異化對比
💡 請求示例(透過渠道 ID):
const response = await fetch('/api/ratio_sync/fetch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_root_token',
'New-Api-User': 'your_user_id'
},
body: JSON.stringify({
channel_ids: [1, 2, -100],
timeout: 10
})
});
const data = await response.json();💡 請求示例(透過自定義 URL):
const response = await fetch('/api/ratio_sync/fetch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_root_token',
'New-Api-User': 'your_user_id'
},
body: JSON.stringify({
upstreams: [
{
name: "自定義源",
base_url: "https://example.com",
endpoint: "/api/ratio_config"
}
],
timeout: 15
})
});
const data = await response.json();✅ 成功響應示例:
{
"success": true,
"data": {
"differences": {
"gpt-4": {
"model_ratio": {
"current": 15.0,
"upstreams": {
"OpenAI官方(1)": 20.0,
"官方倍率預設(-100)": "same"
},
"confidence": {
"OpenAI官方(1)": true,
"官方倍率預設(-100)": true
}
}
},
"claude-3-sonnet": {
"model_price": {
"current": null,
"upstreams": {
"Claude API(2)": 0.003
},
"confidence": {
"Claude API(2)": true
}
}
}
},
"test_results": [
{
"name": "OpenAI官方(1)",
"status": "success"
},
{
"name": "Claude API(2)",
"status": "error",
"error": "連線超時"
}
]
}
}❗ 失敗響應示例:
{
"success": false,
"message": "無有效上游渠道"
}🧾 欄位說明:
-
channel_ids(陣列): 要同步的渠道 ID 列表,可選 -
upstreams(陣列): 自定義上游配置列表,可選name(字串): 上游名稱base_url(字串): 基礎 URL,必須以 http 開頭endpoint(字串): 介面端點,預設為"/api/ratio_config"
-
timeout(數字): 請求超時時間(秒),預設為 10 秒 -
differences(物件): 差異化倍率對比結果- 鍵為模型名稱,值包含各倍率型別的差異資訊
current: 本地當前值upstreams: 各上游的值,"same"表示與本地相同confidence: 資料可信度,false 表示可能不可信
-
test_results(陣列): 各上游的測試結果