> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yelu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 列出模型

> 以兼容 OpenAI 的格式列出当前 Yelu API Key 可以访问的 AI 模型。

返回当前 API Key 可用的模型 ID。配置应用或刷新模型目录时应调用本端点，不要假设所有供应商模型都已开启。

## 端点

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
GET https://api.yelu.ai/v1/models
```

## 请求头

<ParamField header="Authorization" type="string" required>
  API Key，格式为 `Bearer $YELU_API_KEY`。
</ParamField>

## 请求体

本端点不接受请求体。

## 响应

<ResponseField name="object" type="string" required>兼容 OpenAI 的模型集合固定为 `list`。</ResponseField>

<ResponseField name="data" type="array" required>
  当前 Key 可访问的模型。

  <Expandable title="模型字段">
    <ResponseField name="id" type="string" required>请求中使用的模型 ID。</ResponseField>
    <ResponseField name="object" type="string" required>对象类型，通常为 `model`。</ResponseField>
    <ResponseField name="created" type="integer">模型目录条目关联的 Unix 时间戳。</ResponseField>
    <ResponseField name="owned_by" type="string">模型供应商或组织标识。</ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl https://api.yelu.ai/v1/models \
    -H "Authorization: Bearer $YELU_API_KEY"
  ```

  ```javascript JavaScript (Fetch) theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const response = await fetch('https://api.yelu.ai/v1/models', {
    headers: { Authorization: `Bearer ${process.env.YELU_API_KEY}` },
  });
  if (!response.ok) throw new Error(await response.text());
  console.log((await response.json()).data.map(({ id }) => id));
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import requests

  response = requests.get(
      "https://api.yelu.ai/v1/models",
      headers={"Authorization": f"Bearer {os.environ['YELU_API_KEY']}"},
      timeout=30,
  )
  response.raise_for_status()
  print([model["id"] for model in response.json()["data"]])
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={"theme":{"light":"github-light","dark":"github-dark"}}
  {
    "object": "list",
    "data": [
      {"id":"gpt-4o-mini","object":"model","created":1721172741,"owned_by":"openai"},
      {"id":"claude-3-7-sonnet","object":"model","created":1740096000,"owned_by":"anthropic"}
    ]
  }
  ```

  ```json 401 theme={"theme":{"light":"github-light","dark":"github-dark"}}
  {"error":{"message":"Invalid API key.","type":"authentication_error","param":null,"code":"invalid_api_key"}}
  ```
</ResponseExample>

## 错误码

| 状态码   | 类型                     | 含义                 |
| ----- | ---------------------- | ------------------ |
| `401` | `authentication_error` | Bearer Token 缺失或无效 |
| `403` | `permission_denied`    | Key 或账号被禁用或受限      |
| `429` | `rate_limit_error`     | 达到请求限制             |
| `500` | `server_error`         | 网关无法构建模型目录         |

<Note>模型出现在目录中代表可以路由；视觉、工具、JSON Schema、音频或图像生成等能力仍取决于具体模型。</Note>
