# Models & Pricing (System Advanced API)

Query the models available to the current account, base billing rates, site-wide/scheduled discounts, **current user-tier discount and per-model exclusive discounts**, and model price/discount change history using an Account Permission Key (`tb_acct_...`).

> [!IMPORTANT]
> - **Authentication & Security Tips**: Pass `Authorization: Bearer tb_acct_...` or `X-Account-Api-Key: tb_acct_...` in the request header; enabling two-factor authentication (2FA) on your account is recommended to improve key security.
> - **Exclusive Discounts & Floor Price Protection**: If the current account has a per-model exclusive discount configured, the response returns `user_model_discount`; when constrained by the site-wide floor price, it is automatically clamped to the floor price and `user_model_discount_limited` is `true`.

---

### 1. List Available Models & Pricing Discounts

Retrieve the list of models visible to the current user and backed by available channels, including billing unit prices (`billing`), site promotional/scheduled discounts, user-tier discounts, per-model exclusive user discounts, and final effective discounts, with support for keyword/category filtering and inline recent price adjustment history.

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

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `keyword` | `string` | None | Fuzzy filter by `model_id`, `mid`, `display_name`, or `original_id` |
| `category` | `string` | All | Exact filter by model category (e.g., `chat`, `image`, `video`, `audio`) |
| `include_price_history` | `integer` | `0` | Pass `1` to include the recent price adjustment array `price_history` for each model |
| `history_limit` | `integer` | `10` | Maximum number of history entries returned per model when `include_price_history=1` (range `1–50`) |

* **Request Example (Curl)**:

```bash
curl -s "https://www.tokenpad.ai/api/open/v1/models?keyword=gpt&include_price_history=1&history_limit=5" \
  -H "Authorization: Bearer tb_acct_your_account_key"
```

* **Response Example**:

```json
{
  "data": [
    {
      "id": 12,
      "mid": "m_gpt4o",
      "model_id": "gpt-4o",
      "original_id": "gpt-4o-2024-11-20",
      "display_name": "GPT-4o",
      "category": "chat",
      "provider": "OpenAI",
      "billing_invalid": false,
      "billing": {
        "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,
        "resolution_discounts": null,
        "user_level_discount": 0.9,
        "user_model_discount": 0.7,
        "user_model_discount_limited": false,
        "effective_discount": 0.7
      },
      "price_history": [
        {
          "id": 108,
          "model_id": 12,
          "mid": "m_gpt4o",
          "model_key": "gpt-4o",
          "original_id": "gpt-4o-2024-11-20",
          "model_name": "GPT-4o",
          "provider_name": "OpenAI",
          "type_name": "chat",
          "change_type": "discount",
          "change_summary": "Site-wide discount adjustment: 1.0 -> 0.85",
          "previous_discount": 1.0,
          "current_discount": 0.85,
          "previous_snapshot": { "effective_discount": 1.0 },
          "current_snapshot": { "effective_discount": 0.85 },
          "created_at": "2026-11-12 12:00:00 (UTC+8)"
        }
      ]
    }
  ],
  "total": 1
}
```

* **`discounts` Core Fields**:

| Field | Description |
| :--- | :--- |
| `global_discount_enabled` / `global_discount` | Whether the site-wide discount is enabled (`1`/`0`) and the currently active site discount factor (e.g., `0.85` means 15% off) |
| `base_global_discount` | When a scheduled discount plan (`discount_schedule`) is active, returns the base site discount before the scheduled override takes effect |
| `user_level_discount` | Base discount factor for the current account's user tier |
| `user_model_discount` | Per-model exclusive discount individually configured by an admin for the current user (`null` if not configured) |
| `user_model_discount_limited` | If `true`, indicates that the original exclusive discount was raised to the model floor price due to floor price protection |
| `effective_discount` | Actual minimum effective discount currently applied after combining account discount policies and floor price rules |

---

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

Query pricing or discount change records for models visible to the current user (initial baseline records are filtered out).

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

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `model_id` | `string` | None | Filter by a single model's numeric `id`, `mid`, `model_id`, `original_id`, or display name |
| `ids` | `string` | None | Batch filter by comma-separated numeric model `id` values (e.g., `12,18,25`); takes precedence over `model_id` |
| `change_type` | `string` | `all` | Filter by change type (e.g., `price`, `discount`; leave empty or `all` to return all non-initial changes) |
| `limit` | `integer` | `50` | Maximum number of records returned (range `1–200`, sorted in reverse chronological order) |

* **Request Example (Curl)**:

```bash
curl -s "https://www.tokenpad.ai/api/open/v1/models/price-history?model_id=gpt-4o&limit=20" \
  -H "Authorization: Bearer tb_acct_your_account_key"
```

---

### 3. Query Price Change History for a Single Model

Quickly query historical price/discount change details for a specified model by path parameter.

* **Path**: `GET /api/open/v1/models/{id}/price-history`
* **Path Parameter**: `id` accepts the model's numeric `id`, `mid` (e.g., `m_gpt4o`), `model_id` (e.g., `gpt-4o`), or `original_id`
* **Query Parameters (Query)**: Supports `change_type` and `limit` (range `1–200`, default `50`)
* **Request Example (Curl)**:

```bash
curl -s "https://www.tokenpad.ai/api/open/v1/models/gpt-4o/price-history?limit=10" \
  -H "Authorization: Bearer tb_acct_your_account_key"
```

* **Response Example**:

```json
{
  "items": [
    {
      "id": 108,
      "model_id": 12,
      "mid": "m_gpt4o",
      "model_key": "gpt-4o",
      "original_id": "gpt-4o-2024-11-20",
      "model_name": "GPT-4o",
      "provider_name": "OpenAI",
      "type_name": "chat",
      "change_type": "discount",
      "change_summary": "Site-wide discount adjustment: 1.0 -> 0.85",
      "previous_discount": 1.0,
      "current_discount": 0.85,
      "previous_snapshot": { "effective_discount": 1.0 },
      "current_snapshot": { "effective_discount": 0.85 },
      "created_at": "2026-11-12 12:00:00 (UTC+8)"
    }
  ],
  "total": 1
}
```
