1.接口描述
- | 描述 |
接口名称 | 模型列表 |
请求路径 | https://wishub-x1.ctyun.cn/v1/models |
功能描述 | 用于获取用户模型列表 |
2.请求参数
请求头参数
参数 | 示例值 | 描述 |
Authorization | Bearer AppKey | 鉴权信息填入AppKey。 |
Content-Type | application/json |
|
3.请求返回
3.1请求正常返回
字段名称 | 二级字段 | 字段类型 | 描述 |
object |
| string | 返回的对象类型,默认为list
|
data |
| array | 模型列表 |
- | id | string | 模型id或者模型名称
|
- | object
| string | 默认为model |
| created | string | 创建时间,默认为空 |
- | owned_by | string | 组织 机构,默认为空 |
返回结果示例
{
"object":"list",
"data":[
{
"id":"测试模型名称1",
"object":"model",
"created":"",
"owned_by":""
}
]
}
3.2异常返回
异常返回时:
http code 返回非200。
http body 中返回 error 结构,error结构中包含code、type、message、param等信息,具体可见错误处理章节内容。
错误结果示例
{
"code":500004,
"detail":"AppKey不正确,请使用正确的AppKey",
"message":"INCORRECT_API_KEY_PROVIDED",
"error":{
"code":"500004",
"message":"AppKey不正确,请使用正确的AppKey",
"type":"INCORRECT_API_KEY_PROVIDED"
}
}
4.请求示例代码
假设平台用户组AppKey=884c8fc4054548a7b1ca1123592f5b7,以此为例进行说明。
4.1 curl方式请求
curl --request get \
--url https://wishub-x1.ctyun.cn/v1/models \
--header 'Accept: */*'\
--header 'Accept-Encoding: gzip, deflate, br'\
--header 'Authorization: Bearer 884c8fc4054548a7b1ca1123592f5b7'\
--header 'Content-Type: application/json'\
4.2 python方式请求
import json
import requests
URL ="https://wishub-x1.ctyun.cn/v1/models"
headers ={
"Authorization":"Bearer 884c8fc4054548a7b1ca1123592f5b7",
"Content-Type":"application/json"
}
try:
response = requests.get(URL, headers=headers)
if response.status_code !=200:
print(response.text)
else:
data = response.json()["data"]
print(data)
except Exception as e:
print(f"Exception: {e}")
4.3 openai 客户端示例代码
import openai
from openai import OpenAI
client = OpenAI(base_url="https://wishub-x1.ctyun.cn/v1/models", api_key="884c8fc4054548a7b1ca1123592f5b7")
try:
response = openai.models.list()
print(f"{response}")
except openai.APIStatusError as e:
print(f"APIStatusError: {e.status_code}, {e.message}, {e.body}")
except openai.APIError as e:
print(f"APIError: {e.body}")
except Exception as e:
print(f"Exception: {e}")