Skip to content

获取模型列表

获取当前用户可访问的所有 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"]
    }
  ]
}

响应字段

顶层字段:

字段类型描述
successboolean请求是否成功
dataarray模型列表数组(仅在成功时返回)
messagestring错误信息(仅在失败时返回)

模型对象字段:

字段类型描述
idstring模型唯一标识符
objectstring对象类型,固定为 model
createdinteger模型创建时间戳
owned_bystring模型所属的服务商
supported_endpoint_typesarray模型支持的 API 端点类型

支持的端点类型

类型说明
chat聊天完成
completion文本完成
embedding文本嵌入
image图像生成
audio音频处理
rerank重排序

注意事项

认证要求

必须提供有效的 API 令牌,令牌决定了用户可以访问哪些模型。

权限控制

返回的模型列表会根据用户分组和令牌分组进行过滤,仅显示用户有权限访问的模型。

常见错误

状态码含义
401 UnauthorizedAPI 令牌无效或已过期
403 Forbidden用户没有访问权限
500 Internal Server Error服务器内部错误