查询余额
客户可通过 API Key(sk_live_ 开头)程序化查询组织余额,无需登录态。接口仅接受 API Key 鉴权,余额为组织级。
鉴权
在请求头携带 API Key:
Authorization: Bearer sk_live_YOUR_API_KEY
API Key 在控制台「API Keys」页面创建,绑定到某个组织与项目。
接口
GET
/api/business/v1/customer/balance查询余额
Return the current balance for the API key's organization. API key only.
🔑
Bearer API Key请求头使用 Authorization: Bearer sk_live_...,也支持 x-api-key。
请求结构
下方内容用于确认方法、地址和鉴权方式,属于 HTTP 结构片段,不是可独立执行示例。
HTTP
GET https://www.silvamux.com/api/business/v1/customer/balance
Authorization: Bearer $SILVAMUX_API_KEY请求参数
| 参数 | 类型与位置 | 必填 | 说明 |
|---|---|---|---|
Authorization | string · header | 是 | Bearer API Key (sk_live_...) |
X-Organization-Id | string · header | 否 | Not required for API key auth |
响应
200OK
application/json · CustomerBalanceResponse
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
$schema | string (uri) | 否 | A URL to the JSON Schema for this object. |
balance_points | string | 是 | Current balance in points |
defaultError
application/problem+json · ErrorModel
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
$schema | string (uri) | 否 | A URL to the JSON Schema for this object. |
detail | string | 否 | A human-readable explanation specific to this occurrence of the problem. |
errors | array<ErrorDetail> | 否 | Optional list of individual error details |
errors.location | string | 否 | Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id' |
errors.message | string | 否 | Error message text |
errors.value | any | 否 | The value at the given location |
instance | string (uri) | 否 | A URI reference that identifies the specific occurrence of the problem. |
status | integer (int64) | 否 | HTTP status code |
title | string | 否 | A short, human-readable summary of the problem type. This value should not change between occurrences of the error. |
type | string (uri) | 否 | A URI reference to human-readable documentation for the error.;默认值:about:blank |
示例
curl https://www.silvamux.com/api/business/v1/customer/balance \
-H "Authorization: Bearer $SILVAMUX_API_KEY"
# pip install requests
import os
import requests
resp = requests.get(
"https://www.silvamux.com/api/business/v1/customer/balance",
headers={"Authorization": f"Bearer {os.environ['SILVAMUX_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json()) # {"balance_points": "42.5"}
// Node 18+(内置 fetch)
const resp = await fetch(
"https://www.silvamux.com/api/business/v1/customer/balance",
{
headers: { Authorization: `Bearer ${process.env.SILVAMUX_API_KEY}` },
},
);
const data = await resp.json();
console.log(data); // { balance_points: "42.5" }
// 仅依赖标准库
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest("GET", "https://www.silvamux.com/api/business/v1/customer/balance", nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SILVAMUX_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
响应:
{
"balance_points": "42.5"
}
| 字段 | 说明 |
|---|---|
balance_points | 当前余额(points) |
错误处理
| HTTP 状态 | 错误码 | 说明 |
|---|---|---|
| 401 | INVALID_TOKEN | API Key 缺失或无效 |