# 高可用相关接口

# 动态获取API地址

对于可用性要求较高的用户,CloseAI提供了动态获取API地址的方式,避免单个域名不可用时导致生产损失,此接口需要通过独立的专用域名访问,且携带平台提供的API Key。接口有限流,不可频繁调用。请对接口返回内容做好缓存,不要每次请求都查询API Base,检测接口有效性应通过健康状态API检测。

接口中的priority提示了该API的推荐优先级,数字越大,越推荐作为优先选择。优先级低仅作为紧急时刻备用选择,替换频率较高。

请求

curl --location --request GET 'https://api.shadowai.xyz/api/v1/links' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-xxxx'

响应

[
    {
        "api": "https://api.xxxx.org",
        "desc": "主API",
        "priority": 10,
        "status": "ok"
    },
    {
        "api": "https://api.xxxx.xyz",
        "desc": "紧急备用API,随时替换,请勿过渡依赖",
        "priority": 1,
        "status": "ok"
    }
]

# 查询API健康状态

通过动态API查询接口返回的API地址,可以通过以下接口查询API健康状态,能正常访问时,说明域名处于健康状态。可以正常提供服务。接口有限流,请合理设置检查频率。不要频繁检查可用性,建议5分钟检测一次即可。

请求

curl --location --request GET '{API Base}/api/v1/healthy' \
--header 'Content-Type: application/json'

响应

healthy

# 子账户相关接口

通过CloseAI提供的主账户sk,可以已类似请求openai的方式,请求CloseAI的开放接口。子账户sk无这类访问权限,不需要担心子账户越权操作。

注意:以下历史参数已经废弃,改为由pricing_factor控制的倍率定价,设置了auto_following的模型会自动转为倍率1倍,其余的模型不会自动转换,需要手动调整。

{
  "prompt_price": 0,
  "completion_price": 0,
  "auto_following": true
}

# 查询子账户信息

请求参数(querystring)

alias: 按别名过滤(可不传)
sk: 按token过滤(可不传)
page: 页码,默认为1(可不传)
page_size: 每页返回的数量,为-1时返回全部(可不传)

请求

curl '{API Base}/api/v1/account/sub-account/list?page=1&page_size=10' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer sk-xxxx'

返回

{
    "items": [
        {
            "id": 123,
            "user_id": 123,
            "token": "sk-xxx",
            "token_type": "slave",
            "alias": "test",
            "enabled": true,
            "model_pricing": [
                {
                    "model": "gpt-3.5-turbo",
                    "pricing_factor": 1
                }
            ],
            "balance": "100",
            "monthly_cost": "0.44000013",
            "created_at": "2023-05-24T23:13:16.878831+08:00",
            "updated_at": "2023-07-05T12:55:30.048657+08:00"
        }
    ],
    "total": 1,
    "page": 1,
    "pageSize": 10
}

# 批量创建子账户

参数释义:

alias: 子账户别名
balance:子账户虚拟余额
model_pricing:子账户可用模型及定价,必须显式指定,不指定则无权限使用
count:批量创建的子账户数量

请求

curl --request POST '{API Base}/api/v1/account/sub-account/token' \
    --data-raw '{"alias":"test","model_pricing":[{"model":"gpt-3.5-turbo","prompt_price":0,"completion_price":0,"auto_following":true},{"model":"gpt-3.5-turbo-16k","prompt_price":0,"completion_price":0,"auto_following":true},{"model":"gpt-4","prompt_price":0,"completion_price":0,"auto_following":true}],"balance":1,"count":1}' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer sk-xxxx'

响应

{
    "items": [
        {
            "id": 123,
            "user_id": 123,
            "token": "sk-xxxx",
            "token_type": "slave",
            "alias": "test",
            "enabled": true,
            "model_pricing": [
                {
                    "model": "gpt-3.5-turbo",
                    "pricing_factor": 1
                },
                {
                    "model": "gpt-3.5-turbo-16k",
                    "pricing_factor": 1
                },
                {
                    "model": "gpt-4",
                    "pricing_factor": 1
                }
            ],
            "balance": "1",
            "monthly_cost": "0",
            "created_at": "2023-07-09T21:23:16.944115+08:00",
            "updated_at": "2023-07-09T21:23:16.944115+08:00"
        }
    ],
    "success": true
}

# 批量编辑子账户模型定价

参数释义:

sks: 需要删除的sk的列表
alias: 子账户别名
model_pricing:子账户可用模型及定价,必须显式指定,不指定则无权限使用

请求

curl --request POST '{API Base}/api/v1/account/sub-account/token/info' \
  --data-raw '{"sks":["sk-123"],"alias":"ee4","model_pricing":[{"model":"gpt-3.5-turbo","pricing_factor": 1}]}' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk-xxxx'

响应

{"success":true}

# 批量删除子账户

参数释义:

sks: 需要删除的sk的列表

请求

curl --request DELETE '{API Base}/api/v1/account/sub-account/token' \
  --data-raw '{"sks":["sk-xxxx"]}' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk-xxxx'

响应

{"success":true}