# OpenAI兼容接口

# 模型相关接口

以下接口为CloseAI已经支持的接口,参数与使用方式全部同OpenAI,文档见《OpenAI官方API文档》 (opens new window) ,可以直接使用,无需任何修改。

接口 能力 用法
/v1/chat/completions 文本 和官网一致
/v1/completions 文本 和官网一致
/v1/embeddings 文本 和官网一致
/v1/images/generations 图像 和官网一致
/v1/images/edits 图像 和官网一致
/v1/images/variations 图像 和官网一致
/v1/audio/speech 音频 和官网一致
/v1/audio/transcriptions 音频 和官网一致
/v1/audio/translations 音频 和官网一致
/v1/models 其他 和官网一致
/v1/models/{model} 其他 和官网一致

TIP

注意:页面没写的接口即不支持,平台转发基于负载均衡技术,不支持fine-tune、assistants等有状态接口。

# 资金相关接口

TIP

接口有限流,请不要高频调用

为了兼容某些前端项目的余额查询需求,也为了部分用户可以通过接口查询余额,平台按照OpenAI的接口格式返回了余额等信息

接口 作用
/dashboard/billing/usage 查询指定时间段的消费金额
/dashboard/billing/credit_grants 查询当前余额

# 请求样例

查询指定时间段的消费金额:/dashboard/billing/usage

curl --location --request GET ' https://api.openai-proxy.org/dashboard/billing/usage?start_date=2023-04-01&end_date=2023-06-01' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-xxxx'
{
    "object": "list",
    "daily_costs": null,
    "total_usage": 88.96
}

查询当前余额:/dashboard/billing/credit_grants

curl --location --request GET ' https://api.openai-proxy.org/dashboard/billing/credit_grants' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-xxxx'
{
  "object": "credit_summary",
  "total_granted": 194.98,  //无实际意义,可能某些前端会用到,不要依赖这个字段
  "total_used": 80,  //本月消费
  "total_available": 194.98  //剩余余额
}