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

# 列出模型

> 获取当前可用的模型列表

## 简介

获取当前可用的模型列表。本接口支持自动识别返回格式，无需手动指定。

## 自动格式识别

根据请求头自动返回对应格式：Anthropic、Gemini 或 OpenAI 格式

## 认证

Bearer Token，如 `Bearer sk-xxxxxxxxxx`

## 请求头说明

根据请求头自动识别返回格式：

**x-anthropic-version** `string`

返回 Anthropic 格式响应

**x-goog-api-key** `string`

返回 Gemini 格式响应

> [!NOTE]
>
> 默认返回 OpenAI 格式响应

## 代码示例

**cURL**

```bash theme={null}
curl https://api.mixroute.ai/v1/models \
  -H "Authorization: Bearer sk-xxxxxxxxxx"
```

**Python**

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxxxxxx",
    base_url="https://api.mixroute.ai/v1"
)

models = client.models.list()

for model in models.data:
    print(f"Model ID: {model.id}, Provider: {model.owned_by}")
```

**Node.js**

```javascript theme={null}
const axios = require('axios');

const response = await axios.get('https://api.mixroute.ai/v1/models', {
  headers: {
    'Authorization': 'Bearer sk-xxxxxxxxxx'
  }
});

console.log(response.data.data);
```

## 响应字段说明

| 字段 | 类型 | 说明 |
| - | - | - |
| object | string | 固定为 `list` |
| data | array | 模型列表 |
| data\[].id | string | 模型唯一标识 |
| data\[].object | string | 固定为 `model` |
| data\[].created | integer | 模型创建时间戳（Unix 时间戳） |
| data\[].owned\_by | string | 模型提供商（如：openai、anthropic、google） |

## 响应示例

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "id": "gpt-5.5",
      "object": "model",
      "created": 1715232000,
      "owned_by": "openai"
    },
    {
      "id": "claude-opus-4-8",
      "object": "model",
      "created": 1743465600,
      "owned_by": "anthropic"
    },
    {
      "id": "gemini-3.5-flash",
      "object": "model",
      "created": 1746057600,
      "owned_by": "google"
    }
  ]
}
```

## HTTP 状态码

| 状态码 | 说明 |
| - | - |
| 200 | 请求成功 |
| 401 | API Key 无效或已过期 |
| 429 | 请求频率过高 |
| 500 | 服务器内部错误 |

## 错误响应示例

```json theme={null}
{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
```

## 注意事项

* 建议缓存模型列表，避免频繁请求（推荐缓存 1 小时）
* 返回的模型列表会根据您的 API Key 权限动态变化
* 可在应用启动时调用此接口进行可用性检查
* 不同模型的 `created` 时间戳可能差异较大，仅代表模型发布时间
* Python 示例依赖 `openai` 库：`pip install openai`
* Node.js 示例依赖 `axios` 库：`npm install axios`

```bash cURL theme={null}
curl --request GET \
  --url https://api.mixroute.ai/v1/models \
  --header 'Authorization: Bearer sk-xxxxxxxxxx'
```

```python Python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxxxxxx",
    base_url="https://api.mixroute.ai/v1"
)

models = client.models.list()
for model in models.data:
    print(f"Model ID: {model.id}")
```

```javascript JavaScript theme={null}
const response = await fetch('https://api.mixroute.ai/v1/models', {
  headers: {
    'Authorization': 'Bearer sk-xxxxxxxxxx'
  }
});
const data = await response.json();
console.log(data.data);
```

```php PHP theme={null}
<?php
$client = new GuzzleHttp\Client();
$response = $client->get('https://api.mixroute.ai/v1/models', [
    'headers' => [
        'Authorization' => 'Bearer sk-xxxxxxxxxx'
    ]
]);
echo $response->getBody();
```

```go Go theme={null}
package main

import (
    "net/http"
)

func main() {
    req, _ := http.NewRequest("GET", "https://api.mixroute.ai/v1/models", nil)
    req.Header.Set("Authorization", "Bearer sk-xxxxxxxxxx")
    http.DefaultClient.Do(req)
}
```

```java Java theme={null}
import java.net.http.*;
import java.net.URI;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mixroute.ai/v1/models"))
    .header("Authorization", "Bearer sk-xxxxxxxxxx")
    .GET()
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

```ruby Ruby theme={null}
require 'net/http'
require 'json'

uri = URI('https://api.mixroute.ai/v1/models')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer sk-xxxxxxxxxx'

response = http.request(request)
puts response.body
```

```json Response theme={null}
{
  "object": "list",
  "data": [
    {
      "id": "gpt-5.5",
      "object": "model",
      "created": 1715232000,
      "owned_by": "openai"
    },
    {
      "id": "claude-opus-4-8",
      "object": "model",
      "created": 1743465600,
      "owned_by": "anthropic"
    }
  ]
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.