# Modèles et tarification (API Avancée)

Use your **Account Permission Key** to query models available to your account, base billing rates, site/scheduled discounts, user-tier and per-model exclusive discounts, and price/discount change history.

> [!IMPORTANT]
> - **Base URL**: `https://ai.artsmcp.com/api/open/v1`
> - **Auth Header (Choose One)**: `Authorization: Bearer <your_account_key>`, `X-Account-Api-Key: <your_account_key>`, or `X-Api-Key: <your_account_key>`
> - **Model Identifiers**: Every model has a unique cross-endpoint `mid` (e.g., `308750`) and a callable `model_id` (e.g., `gpt-4o`); when a per-model exclusive discount reaches the minimum discount threshold, `user_model_discount_limited` is `true`

---

### 1. List Available Models & Pricing Discounts

Retrieve available models with billing rates (`billing`), site/scheduled discounts, user-tier discounts, per-model exclusive discounts, and effective discounts, with optional keyword/category filters and inline price history.

* **Path**: `GET /api/open/v1/models`
* **Query Parameters**:

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `keyword` | `string` | None | Fuzzy filter by `model_id`, `mid`, `display_name`, or `original_id` |
| `category` | `string` | All | Filter by category: `chat`, `image`, `video`, `audio`, `embedding`, `rerank` (also supports localized category names) |
| `include_price_history` | `integer` | `0` | Pass `1` to include recent `price_history` entries for each model |
| `history_limit` | `integer` | `10` | Max history entries per model when `include_price_history=1` (`1..50`) |

* **Example (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>"
```

* **Response Example**:

```json
{
  "data": [
    {
      "mid": "308750",
      "model_id": "gpt-4o",
      "original_id": "gpt-4o-2024-11-20",
      "display_name": "GPT-4o",
      "category": "chat",
      "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
}
```

* **Response Fields**:

| Field | Type | Description |
| :--- | :--- | :--- |
| `data` | `array` | List of available model objects |
| `mid` / `model_id` | `string` | Unique model identifier (`mid`) and callable model identifier (`model_id`) |
| `display_name` / `category` / `provider` | `string` | Display name, category, and provider |
| `api_provider` / `forward_rules` | `string` / `array` | Protocol provider and supported protocol types (`eid` and `name`) |
| `pre_deduction` | `number` | Per-request pre-deduction amount |
| `billing` | `object` | Billing rule details (`pid`, `name`, `billing_type`, `billing_rule`, unit rates, and tier config) |
| `discounts.global_discount_enabled` / `discounts.global_discount` | `integer` / `number` | Site discount toggle (`1`/`0`) and active site discount factor (e.g., `0.85` = 15% off) |
| `discounts.base_global_discount` | `number \| null` | Base site discount prior to an active scheduled discount override |
| `discounts.user_level_discount` | `number` | Base discount factor for the account's user tier |
| `discounts.user_model_discount` | `number \| null` | Per-model exclusive discount for the current account (`null` if unset) |
| `discounts.user_model_discount_limited` | `boolean` | `true` when the exclusive discount reached the minimum discount limit |
| `discounts.effective_discount` | `number` | Actual effective discount factor currently applied |
| `discounts.effective_discount_schedule` | `string` | Account-effective scheduled/limited discount JSON string (empty when inactive) |
| `discounts.user_model_resolution_discounts` / `discounts.user_model_discount_end_at` | `object \| null` / `string \| null` | Per-resolution exclusive discount map and expiration timestamp (`null` if unset) |
| `discounts.regular_effective_discount` / `discounts.peak_effective_discount` | `number` | Regular off-promotion effective discount and full-cycle peak effective discount |
| `discounts.site_timezone` | `string` | Site operating timezone identifier (e.g., `Asia/Shanghai`) |
| `price_history` | `array` | Recent price/discount changes (returned when `include_price_history=1`) |
| `total` | `integer` | Total models returned |

---

### 2. Query Model Price & Discount Change History (Batch / Filtered)

Query pricing or discount change records across models available to the current account (response format matches Section 3).

* **Path**: `GET /api/open/v1/models/price-history`
* **Query Parameters**:

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `mid` | `string` | None | Filter by a single model `mid` (e.g., `308750`) |
| `mids` | `string` | None | Batch filter by comma-separated `mid` values (takes precedence over `mid` and `model_id`) |
| `model_id` | `string` | None | Filter by callable `model_id`, `original_id`, or display name |
| `change_type` | `string` | `all` | Filter by change type: `price`, `discount`, or `all` |
| `limit` | `integer` | `50` | Maximum records returned (`1..200`, newest first) |

* **Example (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. Query Price Change History for a Single Model

Query pricing and discount change history for a single model by its unique `mid`.

* **Path**: `GET /api/open/v1/models/{mid}/price-history`
* **Path Parameter**: `mid` — Unique model identifier (e.g., `308750`, from `GET /api/open/v1/models`)
* **Query Parameters**:

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `change_type` | `string` | `all` | Filter by change type: `price`, `discount`, or `all` |
| `limit` | `integer` | `50` | Maximum records returned (`1..200`, newest first) |

* **Example (Curl)**:

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

* **Response Example**:

```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
}
```

* **Response Fields**:

| Field | Type | Description |
| :--- | :--- | :--- |
| `items` | `array` | Price and discount change history records |
| `items[].mid` / `items[].model_key` | `string` | Unique model identifier and callable model ID |
| `items[].original_id` / `items[].model_name` | `string` | Original model ID and display name |
| `items[].provider_name` / `items[].type_name` | `string` | Provider name and model category |
| `items[].change_type` | `string` | Change type (`price` or `discount`) |
| `items[].previous_discount` / `items[].current_discount` | `number` | Discount factor before and after the change |
| `items[].created_at` | `string` | Effective timestamp in site operating timezone |
| `total` | `integer` | Total records returned |
