获取模型列表
获取当前用户可访问的所有 AI 模型列表,包括模型 ID、所属服务商和详细信息。
模型列表与令牌分组
模型列表返回哪些模型,取决于 API 令牌所在的令牌分组。你可以在 控制台 → API 令牌 页面添加令牌时,选择对应的令牌分组。
列出模型
GET https://ciyuanx.io/v1/models
bash
curl https://ciyuanx.io/v1/models \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://ciyuanx.io/v1",
)
models = client.models.list()
for model in models.data:
print(model.id)typescript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://ciyuanx.io/v1",
});
const models = await client.models.list();
for (const model of models.data) {
console.log(model.id);
}响应
成功响应 (200 OK):
json
{
"success": true,
"data": [
{
"id": "gpt-4",
"object": "model",
"created": 1626777600,
"owned_by": "openai",
"supported_endpoint_types": ["chat", "completion"]
},
{
"id": "claude-3-sonnet-20240229",
"object": "model",
"created": 1626777600,
"owned_by": "anthropic",
"supported_endpoint_types": ["chat"]
}
]
}响应字段
顶层字段:
| 字段 | 类型 | 描述 |
|---|---|---|
success | boolean | 请求是否成功 |
data | array | 模型列表数组(仅在成功时返回) |
message | string | 错误信息(仅在失败时返回) |
模型对象字段:
| 字段 | 类型 | 描述 |
|---|---|---|
id | string | 模型唯一标识符 |
object | string | 对象类型,固定为 model |
created | integer | 模型创建时间戳 |
owned_by | string | 模型所属的服务商 |
supported_endpoint_types | array | 模型支持的 API 端点类型 |
支持的端点类型
| 类型 | 说明 |
|---|---|
chat | 聊天完成 |
completion | 文本完成 |
embedding | 文本嵌入 |
image | 图像生成 |
audio | 音频处理 |
rerank | 重排序 |
注意事项
认证要求
必须提供有效的 API 令牌,令牌决定了用户可以访问哪些模型。
权限控制
返回的模型列表会根据用户分组和令牌分组进行过滤,仅显示用户有权限访问的模型。
常见错误
| 状态码 | 含义 |
|---|---|
401 Unauthorized | API 令牌无效或已过期 |
403 Forbidden | 用户没有访问权限 |
500 Internal Server Error | 服务器内部错误 |