providers: StepFun and StepFun (China) show what is left on the account (StepFun 国外版跟国内版这两个provider都应该支持显示额度) — both answer a key, a Step Plan one too, with the account at /v1/accounts (api.stepfun.ai in dollars, api.stepfun.com in yuan), whose balance is what is left to spend, vouchers included; it is now a card on the Usage page beside the others. Checked against the live api.stepfun.ai with a Step Plan key, on the plan and the pay-as-you-go address. The Step Plan windows are told only to a platform sign-in, not to a key
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package provider
|
||||
|
||||
// What is left on an API key, as the vendor's own balance endpoint tells
|
||||
// it: DeepSeek, Kimi, OpenRouter, SiliconFlow, Command Code and AiHubMix are known by their hosts
|
||||
// it: DeepSeek, Kimi, OpenRouter, SiliconFlow, StepFun, Command Code and AiHubMix are known by their hosts
|
||||
// (AiHubMix tells the whole account's to its access token, BalanceToken);
|
||||
// any other provider can name an endpoint and where the amount sits in its
|
||||
// reply (BalanceURL, BalancePath), the way a relay's own usage query does.
|
||||
@@ -55,6 +55,10 @@ func balanceSourceOf(p Provider) (balanceSource, bool) {
|
||||
return balanceSource{"https://api.siliconflow.cn/v1/user/info", readSiliconFlow("¥"), ""}, true
|
||||
case "api.siliconflow.com":
|
||||
return balanceSource{"https://api.siliconflow.com/v1/user/info", readSiliconFlow("$"), ""}, true
|
||||
case "api.stepfun.com":
|
||||
return balanceSource{"https://api.stepfun.com/v1/accounts", readStepFun("¥"), ""}, true
|
||||
case "api.stepfun.ai":
|
||||
return balanceSource{"https://api.stepfun.ai/v1/accounts", readStepFun("$"), ""}, true
|
||||
case "api.commandcode.ai":
|
||||
return balanceSource{"https://api.commandcode.ai/alpha/billing/credits", readCommandCode, ""}, true
|
||||
case "aihubmix.com":
|
||||
@@ -193,6 +197,27 @@ func readSiliconFlow(sign string) func([]byte) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// readStepFun: {"object":"account","type":"prepaid","balance":26.00,
|
||||
// "total_cash_balance":0.00,"total_voucher_balance":26.00}, balance being
|
||||
// what is left to spend, vouchers included, and the totals what was ever
|
||||
// paid in and given. A Step Plan key tells it too: the plan's key is the
|
||||
// account's, and the account's balance is what it spends past the plan.
|
||||
func readStepFun(sign string) func([]byte) (string, error) {
|
||||
return func(b []byte) (string, error) {
|
||||
var r struct {
|
||||
Balance any `json:"balance"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
v, ok := number(r.Balance)
|
||||
if !ok {
|
||||
return "", errors.New("no balance in the reply")
|
||||
}
|
||||
return money(sign, v), nil
|
||||
}
|
||||
}
|
||||
|
||||
// readAiHubMix: {"object":"list","total_usage":12.5}, what is left on the
|
||||
// key in dollars, despite the name. A key without a limit answers -1 of
|
||||
// AiHubMix's units ($1 is 500000 of them): it has no balance of its own, and
|
||||
|
||||
@@ -23,6 +23,8 @@ func TestBalanceReaders(t *testing.T) {
|
||||
{"commandcode", readCommandCode, `{"credits":{"monthlyCredits":12.3,"purchasedCredits":2,"freeCredits":0},"windowLimits":{"limited":true,"fiveHour":{"used":4.2,"cap":10},"weekly":{"used":9,"cap":50}}}`, "$14.30"},
|
||||
{"commandcode credits only", readCommandCode, `{"credits":{"monthlyCredits":"70"},"windowLimits":null}`, "$70.00"},
|
||||
{"siliconflow", readSiliconFlow("¥"), `{"code":20000,"data":{"balance":"0.88","totalBalance":"88.88"}}`, "¥88.88"},
|
||||
{"stepfun", readStepFun("¥"), `{"object":"account","type":"prepaid","balance":26.00,"total_cash_balance":0.00,"total_voucher_balance":26.00}`, "¥26.00"},
|
||||
{"stepfun intl", readStepFun("$"), `{"object":"account","type":"prepaid","balance":0.00,"total_cash_balance":0.00,"total_voucher_balance":0.00}`, "$0.00"},
|
||||
} {
|
||||
got, err := c.read([]byte(c.body))
|
||||
if err != nil || got != c.want {
|
||||
@@ -81,6 +83,8 @@ func TestBalanceSourceByHost(t *testing.T) {
|
||||
"https://openrouter.ai/api/v1": "https://openrouter.ai/api/v1/credits",
|
||||
"https://api.siliconflow.cn/v1": "https://api.siliconflow.cn/v1/user/info",
|
||||
"https://api.commandcode.ai/provider/v1": "https://api.commandcode.ai/alpha/billing/credits",
|
||||
"https://api.stepfun.com/step_plan/v1": "https://api.stepfun.com/v1/accounts",
|
||||
"https://api.stepfun.ai/v1": "https://api.stepfun.ai/v1/accounts",
|
||||
"https://relay.example.com/v1": "",
|
||||
"https://api.deepseek.com.evil/": "",
|
||||
} {
|
||||
|
||||
Reference in New Issue
Block a user