# 模型與定價（進階介面API）

使用 **帳戶權限金鑰** 唯讀查詢目前帳戶可用的模型清單、計費單價、站點/定時折扣、用戶等級折扣與單模型專屬折扣，以及模型價格/折扣變動歷史。

> [!IMPORTANT]
> - **Base URL**：`https://ai.artsmcp.com/api/open/v1`
> - **驗證請求標頭（三選一）**：`Authorization: Bearer <your_account_key>`、`X-Account-Api-Key: <your_account_key>` 或 `X-Api-Key: <your_account_key>`
> - **模型識別約定**：每個模型的跨介面唯一識別為 `mid`（如 `308750`），對外呼叫識別為 `model_id`（如 `gpt-4o`）；若設定了單模型專屬折扣且觸及最低折扣限制，`user_model_discount_limited` 為 `true`

---

### 1. 取得可用模型清單與定價折扣

取得目前帳戶可用的模型清單，包含計費單價（`billing`）、站點活動/分時段折扣、用戶等級折扣、單模型專屬折扣與最終生效折扣，支援依關鍵字、分類過濾及內嵌回傳近期調價紀錄。

* **路徑**：`GET /api/open/v1/models`
* **查詢參數 (Query)**：

| 參數名 | 類型 | 預設值 | 說明 |
| :--- | :--- | :--- | :--- |
| `keyword` | `string` | 無 | 依 `model_id`、`mid`、`display_name` 或 `original_id` 模糊過濾 |
| `category` | `string` | 全部 | 依模型分類過濾，同時支援英文別名（`chat`、`image`、`video`、`audio`、`embedding`、`rerank`）與站點分類名 |
| `include_price_history` | `integer` | `0` | 傳 `1` 時為每個模型附帶近期調價紀錄陣列 `price_history` |
| `history_limit` | `integer` | `10` | 當 `include_price_history=1` 時每個模型最多回傳的變動筆數（範圍 `1..50`） |

* **呼叫範例 (Curl)**：

```bash
curl -s "https://ai.artsmcp.com/api/open/v1/models?keyword=gpt&include_price_history=1&history_limit=5" \
  -H "Authorization: Bearer <your_account_key>"
```

* **回應範例**：

```json
{
  "data": [
    {
      "mid": "308750",
      "model_id": "gpt-4o",
      "original_id": "gpt-4o-2024-11-20",
      "display_name": "GPT-4o",
      "category": "聊天",
      "provider": "OpenAI",
      "api_provider": "OpenAI",
      "pre_deduction": 1.0,
      "logo": "",
      "description": "",
      "feature_attributes": "",
      "forward_rules": [
        {
          "eid": "openai_chat",
          "name": "OpenAI Chat"
        }
      ],
      "billing_invalid": false,
      "billing": {
        "pid": "73412",
        "name": "GPT-4o",
        "billing_type": "tokens",
        "billing_rule": "token_tiered",
        "prompt_rate": 2.5,
        "completion_rate": 10.0,
        "cached_rate": 1.25,
        "claude_cache_creation_rate": 0.0,
        "claude_cache_read_rate": 0.0,
        "fixed_rate": 0.0,
        "duration_rate": 0.0,
        "pricing_tiers": null,
        "extended_config": {}
      },
      "discounts": {
        "global_discount_enabled": 1,
        "global_discount": 0.85,
        "base_global_discount": null,
        "discount_schedule": null,
        "effective_discount_schedule": "",
        "resolution_discounts": null,
        "user_level_discount": 0.9,
        "user_model_discount": 0.7,
        "user_model_discount_limited": false,
        "user_model_resolution_discounts": null,
        "user_model_discount_end_at": null,
        "effective_discount": 0.7,
        "regular_effective_discount": 0.7,
        "peak_effective_discount": 0.7,
        "site_timezone": "Asia/Shanghai"
      },
      "price_history": [
        {
          "mid": "308750",
          "model_key": "gpt-4o",
          "original_id": "gpt-4o-2024-11-20",
          "model_name": "GPT-4o",
          "provider_name": "OpenAI",
          "type_name": "chat",
          "change_type": "discount",
          "previous_discount": 1.0,
          "current_discount": 0.85,
          "created_at": "2026-11-12 12:00:00 (UTC+8)"
        }
      ]
    }
  ],
  "total": 1
}
```

* **回傳欄位說明**：

| 欄位名 | 類型 | 說明 |
| :--- | :--- | :--- |
| `data` | `array` | 可用模型物件清單 |
| `mid` / `model_id` | `string` | 模型唯一識別碼（`mid`，用於跨介面關聯）與對外呼叫模型識別碼（`model_id`） |
| `display_name` / `category` / `provider` | `string` | 模型顯示名稱、分類與廠商名稱 |
| `api_provider` / `forward_rules` | `string` / `array` | 介面協定供應商及模型支援的協定類型清單（含 `eid` 與 `name`） |
| `pre_deduction` | `number` | 單次請求預扣基準金額 |
| `billing` | `object` | 計費規則詳情，含 `pid`、`name`、`billing_type`、`billing_rule`、各項單價與階梯設定 |
| `discounts.global_discount_enabled` / `discounts.global_discount` | `integer` / `number` | 站點折扣開關（`1`/`0`）及目前生效的站點折扣係數（如 `0.85` 表示 85 折） |
| `discounts.base_global_discount` | `number \| null` | 命中分時段折扣計畫（`discount_schedule`）時，分時段生效前的基礎站點折扣 |
| `discounts.user_level_discount` | `number` | 目前帳戶所屬用戶等級的基礎折扣係數 |
| `discounts.user_model_discount` | `number \| null` | 目前帳戶對該模型的專屬折扣（未設定時為 `null`） |
| `discounts.user_model_discount_limited` | `boolean` | 為 `true` 時表示該專屬折扣已觸及最低折扣限制 |
| `discounts.effective_discount` | `number` | 目前實際生效的折扣係數 |
| `discounts.effective_discount_schedule` | `string` | 目前帳號生效的分時段/限時折扣計畫 JSON 字串（無活動時為空字串） |
| `discounts.user_model_resolution_discounts` / `discounts.user_model_discount_end_at` | `object \| null` / `string \| null` | 單模型依解析度專屬折扣對照與到期時間（未設定時為 `null`） |
| `discounts.regular_effective_discount` / `discounts.peak_effective_discount` | `number` | 常規時段與全週期峰值實際生效折扣 |
| `discounts.site_timezone` | `string` | 站點營運時區識別碼（如 `Asia/Shanghai`），用於解讀分時段與限時活動時間 |
| `price_history` | `array` | 近期調價紀錄（僅 `include_price_history=1` 時回傳） |
| `total` | `integer` | 回傳的模型總數 |

---

### 2. 查詢模型價格與折扣變動歷史（批次 / 篩選）

依模型識別或變更類型查詢目前帳戶可用模型的定價與折扣變更紀錄（回應結構同第 3 節）。

* **路徑**：`GET /api/open/v1/models/price-history`
* **查詢參數 (Query)**：

| 參數名 | 類型 | 預設值 | 說明 |
| :--- | :--- | :--- | :--- |
| `mid` | `string` | 無 | 依單一模型唯一識別碼 `mid` 篩選（如 `308750`） |
| `mids` | `string` | 無 | 依逗號分隔的多個模型 `mid` 批次篩選（如 `308750,308751`），優先權高於 `mid` 與 `model_id` |
| `model_id` | `string` | 無 | 依模型對外呼叫識別碼 `model_id`、`original_id` 或顯示名過濾 |
| `change_type` | `string` | `all` | 變更類型篩選：`price`、`discount` 或 `all`（全部） |
| `limit` | `integer` | `50` | 回傳最大筆數（範圍 `1..200`，依時間倒序） |

* **呼叫範例 (Curl)**：

```bash
curl -s "https://ai.artsmcp.com/api/open/v1/models/price-history?mid=308750&limit=20" \
  -H "Authorization: Bearer <your_account_key>"
```

---

### 3. 查詢單一模型的價格變動歷史

依模型唯一識別碼 `mid` 快速查詢指定模型的歷史價格/折扣變更明細。

* **路徑**：`GET /api/open/v1/models/{mid}/price-history`
* **路徑參數**：`mid` — 模型唯一識別碼（如 `308750`，對應 `GET /api/open/v1/models` 回傳的 `mid`）
* **查詢參數 (Query)**：

| 參數名 | 類型 | 預設值 | 說明 |
| :--- | :--- | :--- | :--- |
| `change_type` | `string` | `all` | 變更類型篩選：`price`、`discount` 或 `all`（全部） |
| `limit` | `integer` | `50` | 回傳最大筆數（範圍 `1..200`，依時間倒序） |

* **呼叫範例 (Curl)**：

```bash
curl -s "https://ai.artsmcp.com/api/open/v1/models/308750/price-history?limit=10" \
  -H "Authorization: Bearer <your_account_key>"
```

* **回應範例**：

```json
{
  "items": [
    {
      "mid": "308750",
      "model_key": "gpt-4o",
      "original_id": "gpt-4o-2024-11-20",
      "model_name": "GPT-4o",
      "provider_name": "OpenAI",
      "type_name": "chat",
      "change_type": "discount",
      "previous_discount": 1.0,
      "current_discount": 0.85,
      "created_at": "2026-11-12 12:00:00 (UTC+8)"
    }
  ],
  "total": 1
}
```

* **回傳欄位說明**：

| 欄位名 | 類型 | 說明 |
| :--- | :--- | :--- |
| `items` | `array` | 調價與折扣變更紀錄清單 |
| `items[].mid` / `items[].model_key` | `string` | 模型唯一識別碼與對外呼叫識別碼 |
| `items[].original_id` / `items[].model_name` | `string` | 模型原始識別碼與顯示名稱 |
| `items[].provider_name` / `items[].type_name` | `string` | 供應商名稱與模型分類 |
| `items[].change_type` | `string` | 變更類型（`price` 定價變更 / `discount` 折扣變更） |
| `items[].previous_discount` / `items[].current_discount` | `number` | 變更前與變更後的折扣係數（折扣變更時回傳） |
| `items[].created_at` | `string` | 變更生效時間（依站點營運時區格式化） |
| `total` | `integer` | 回傳紀錄總數 |
