List models
Lists the currently available models, and provides basic information about each one such as the owner and availability.
端点:GET https://khb.net.cn/v1/models
Authorization
设置请求头 Authorization: Bearer {your API key} 进行身份验证。
Query Parameters
type (string, optional)
按模型主类型筛选。可选值:
text– 文本类(对话、嵌入、重排序等)image– 图像类(图片生成、图生图等)audio– 语音类(语音合成、语音转文本等)video– 视频类(视频生成等)
sub_type (string, optional)
按模型子类型筛选,可在不设置 type 的情况下独立过滤模型。可选值:
chat– 对话模型embedding– 嵌入模型reranker– 重排序模型text-to-image– 文生图image-to-image– 图生图speech-to-text– 语音转文本text-to-video– 文生视频
代码示例
cURL
curl --request GET \
--url https://khb.net.cn/v1/models \
--header 'Authorization: Bearer YOUR_API_KEY'
Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://khb.net.cn/v1"
)
# 获取所有模型
all_models = client.models.list()
for model in all_models.data:
print(f"{model.id} - owned_by: {model.owned_by}")
# 只获取对话模型
chat_models = client.models.list(type="text", sub_type="chat")
print(f"\n对话模型数量: {len(chat_models.data)}")
JavaScript
const options = {
method: 'GET',
headers: {Authorization: 'Bearer YOUR_API_KEY'}
};
fetch('https://khb.net.cn/v1/models', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Response Body
{
"object": "list",
"data": [
{
"id": "Qwen/Qwen2.5-72B-Instruct",
"object": "model",
"created": 1741685396,
"owned_by": "khb"
},
{
"id": "deepseek-ai/DeepSeek-V3",
"object": "model",
"created": 1741685396,
"owned_by": "khb"
}
]
}
使用建议
- 建议在应用启动时调用此接口获取最新模型列表,缓存到本地
- 模型 ID 区分大小写,需与 模型广场 完全一致
- 已下线的模型仍可能返回,但调用时会返回 400 错误
错误码
| 状态码 | 说明 |
|---|---|
| 200 | 查询成功 |
| 401 | API Key 无效 |
| 403 | 权限不足 |
| 404 | 资源不存在 |
| 429 | 触发 Rate Limits |
| 500/503/504 | 服务端错误 |
