> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tramlabs.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tramlabs.io/_mcp/server.

# Models

> Một API cho hàng trăm model

### Một API duy nhất cho hàng trăm model

Trạm AI cung cấp quyền truy cập hơn 300 model AI từ nhiều provider khác nhau thông qua một API duy nhất.

Để duyệt, so sánh và lọc model theo khả năng, giá cả, tốc độ và nhiều tiêu chí khác, hãy truy cập [trang danh sách Models](https://tramlabs.io/models).

## Models API (`/v1/models`)

Tương thích với [OpenAI Models API](https://platform.openai.com/docs/api-reference/models/list). Trả về danh sách các model hiện có.

**`lines`**

```bash lines
curl "https://api.tramlabs.io/v1/models" \
  -H "Authorization: Bearer $TRAM_AI_API_KEY"
```

### Response

**`lines`**

```json lines
{
  "data": [
    {
      "id": "gemini-3.5-flash",
      "object": "model",
      "created": 1719900000,
      "owned_by": "google",
      "mode": "chat"
    }
  ],
  "object": "list"
}
```

## Public Models API (`/public/models`)

Endpoint công khai (không cần xác thực) cung cấp thông tin chi tiết về tất cả các model, bao gồm giá cả, khả năng, thống kê sử dụng và thông tin provider. Đây là nguồn dữ liệu cho [trang Models](https://tramlabs.io/models).

**`lines`**

```bash lines
curl "https://api.tramlabs.io/public/models"
```

### Cấu trúc response

**`lines`**

```json lines
{
  "models": [
    /* Array of PublicModel objects */
  ]
}
```

### Cấu trúc đối tượng PublicModel

Mỗi model trong mảng `models` sẽ bao gồm các trường sau:

| Trường                       | Kiểu dữ liệu                 | Mô tả                                                                                                                                  |
| ---------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `modelName`                  | `string`                     | Tên model dùng trong request API (ví dụ: `"gemini-3.5-flash"`)                                                                         |
| `displayName`                | `string`                     | Tên hiển thị thân thiện với người dùng (ví dụ: `"Gemini 3.5 Flash"`)                                                                   |
| `mode`                       | `string \| null`             | Loại model: `chat`, `completion`, `embedding`, `image_generation`, `video_generation`, `audio_speech`, `audio_transcription`, `rerank` |
| `providers`                  | `Provider[]`                 | Danh sách các provider cung cấp model này                                                                                              |
| `contextLength`              | `number \| null`             | Kích thước context window tối thiểu (tokens) — "from \{context}" floor                                                                 |
| `contextVaries`              | `boolean`                    | `true` nếu context length khác nhau giữa các provider                                                                                  |
| `maxTokens`                  | `number \| null`             | Số token tối đa trong response (max across providers)                                                                                  |
| `inputCostPerToken`          | `number \| null`             | Chi phí mỗi input token (VND). `null` nếu chưa có giá                                                                                  |
| `inputCostVaries`            | `boolean`                    | `true` nếu giá input khác nhau giữa các provider hoặc có tiered pricing                                                                |
| `outputCostPerToken`         | `number \| null`             | Chi phí mỗi output token (VND). `null` nếu chưa có giá                                                                                 |
| `outputCostVaries`           | `boolean`                    | `true` nếu giá output khác nhau giữa các provider hoặc có tiered pricing                                                               |
| `outputCostPerSecondVnd`     | `number \| null`             | Chi phí mỗi giây video output (VND). Chỉ video models                                                                                  |
| `inputCostPerCharacterVnd`   | `number \| null`             | Chi phí mỗi ký tự input (VND). Chỉ TTS models (ElevenLabs)                                                                             |
| `inputCostPerSecondVnd`      | `number \| null`             | Chi phí mỗi giây audio input (VND). Chỉ STT models                                                                                     |
| `outputCostPerImageVnd`      | `number \| null`             | Chi phí mỗi ảnh tạo ra (VND). Flat-fee image models                                                                                    |
| `outputCostPerImageTokenVnd` | `number \| null`             | Chi phí mỗi image output token (VND)                                                                                                   |
| `outputCostPerAudioTokenVnd` | `number \| null`             | Chi phí mỗi audio output token (VND)                                                                                                   |
| `inputCostPerQueryVnd`       | `number \| null`             | Chi phí mỗi rerank query (VND). Rerank models                                                                                          |
| `capabilities`               | `Record<string, boolean>`    | Các khả năng của model (xem bảng bên dưới)                                                                                             |
| `description`                | `{ vi: string, en: string }` | Mô tả chi tiết về model theo ngôn ngữ                                                                                                  |
| `tags`                       | `string[] \| null`           | Các tag phân loại model                                                                                                                |
| `createdAt`                  | `number \| null`             | Thời gian Unix khi model được thêm vào                                                                                                 |
| `stats`                      | `ModelUsageStats \| null`    | Thống kê sử dụng 7 ngày gần nhất. `null` nếu chưa có dữ liệu                                                                           |
| `videoConstraints`           | `VideoConstraints \| null`   | Ràng buộc video (chỉ khi `mode` là `video_generation`). Xem [API Reference](/api/endpoints/models#video-constraints)                   |

#### Đối tượng Provider

**`lines`**

```typescript lines
{
  "key": string,         // Provider key (ví dụ: "openai", "anthropic", "azure")
  "displayName": string  // Tên hiển thị (ví dụ: "OpenAI", "Anthropic", "Azure OpenAI")
}
```

#### Đối tượng ModelUsageStats

**`lines`**

```typescript lines
{
  "tokensWeek": number,                  // Tổng token sử dụng trong 7 ngày qua
  "avgLatencyMs": number | null,         // Latency trung bình (ms)
  "throughputTokensPerSec": number | null // Tốc độ sinh token (tokens/giây, chỉ streaming)
}
```

#### Các khả năng (Capabilities)

Trường `capabilities` cho biết các tính năng mà model hỗ trợ:

* `supports_vision` - Xử lý hình ảnh đầu vào
* `supports_function_calling` - Gọi hàm (Function/Tool calling)
* `supports_response_schema` - Ép buộc định dạng đầu ra theo JSON schema
* `supports_prompt_caching` - Hỗ trợ prompt caching
* `supports_reasoning` - Chế độ suy luận nội bộ (Reasoning)
* `supports_computer_use` - Điều khiển máy tính
* `supports_pdf_input` - Đọc file PDF đầu vào

### Chi tiết một model (`/public/models/:model`)

**`lines`**

```bash lines
curl "https://api.tramlabs.io/public/models/Gemini%203.5%20Flash"
```

Trả về thông tin chi tiết kèm danh sách các provider (routes) với giá và cấu hình riêng:

**`lines`**

```json lines
{
  "model": {
    "modelName": "gemini-3.5-flash",
    "displayName": "Gemini 3.5 Flash",
    "mode": "chat",
    "description": { "vi": "...", "en": "..." },
    "tags": ["fast", "multimodal"],
    "capabilities": { "supports_vision": true, "supports_function_calling": true },
    "contextLength": 1048576,
    "inputCostPerToken": 0.5,
    "outputCostPerToken": 2.0,
    "videoConstraints": null,
    "stats": { "tokensWeek": 1250000, "avgLatencyMs": 450, "throughputTokensPerSec": 120 },
    "activity": { "days": [{ "date": "2026-07-22", "tokens": 150000 }], "totalTokens": 5400000 },
    "routes": [
      {
        "provider": { "key": "google", "displayName": "Google" },
        "contextLength": 1048576,
        "maxTokens": 65536,
        "inputCostPerToken": 0.5,
        "outputCostPerToken": 2.0,
        "stats": { "throughputTokensPerSec": 120, "avgLatencyMs": 450 }
      }
    ]
  }
}
```

### Bảng xếp hạng model (`/public/models/rankings`)

**`lines`**

```bash lines
# Xếp hạng theo tuần (mặc định)
curl "https://api.tramlabs.io/public/models/rankings"

# Xếp hạng theo ngày hoặc tháng
curl "https://api.tramlabs.io/public/models/rankings?period=today"
curl "https://api.tramlabs.io/public/models/rankings?period=month"
```

**`lines`**

```json lines
{
  "period": "week",
  "rankings": [
    {
      "rank": 1,
      "modelName": "gemini-3.5-flash",
      "tokens": 1250000,
      "trendPct": 15.3
    }
  ]
}
```

> **Note**
>
> **Mỗi model có cách tách từ (Tokenize) văn bản khác nhau**
>
> Một số model chia nhỏ văn bản thành các cụm gồm nhiều ký tự (như GPT, Claude, Llama, v.v.), trong khi một số khác lại tách nhỏ theo từng ký tự đơn lẻ (như PaLM). Điều này đồng nghĩa với việc số lượng token (và kéo theo là chi phí) sẽ có sự chênh lệch giữa các model, ngay cả khi người dùng truyền vào cùng một dữ liệu đầu vào và nhận về cùng một kết quả đầu ra.
>
> Chi phí hiển thị và hóa đơn sẽ được tính dựa trên bộ tách token (tokenizer) của chính model đang sử dụng. Người dùng có thể kiểm tra trường `usage` trong dữ liệu phản hồi trả về để nắm được số lượng token chính xác của cả phần input lẫn output.