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

# API User Guide

Prefix the paths below with your service URL. Obtain an access token first, then send it in the `Authorization` header when calling other endpoints. Keep your credentials and token secure. Obtaining a new token invalidates the previous one.

## 1.Get an access token

`POST /wapi/token/` with a JSON body:

```http theme={null}
Content-Type: application/json
```

```json theme={null}
{
  "username": "your_email@example.com",
  "passwd": "your_password"
}
```

<table>
  <colgroup>
    <col width="100" />

    <col width="403" />
  </colgroup>

  <thead>
    <tr>
      <th>**Field**</th>
      <th>**Description**</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`username`</td>
      <td>Account email; required</td>
    </tr>

    <tr>
      <td>`passwd`</td>
      <td>Account password; required</td>
    </tr>
  </tbody>
</table>

On success, use `results.token` as your access token:

```json theme={null}
{
  "code": 200,
  "results": { "token": "YOUR_TOKEN" }
}
```

Accounts that have purchased a Dynamic GB or Premium Dynamic GB package, or redeemed Dynamic traffic, can obtain a token. This endpoint is rate-limited; retry later if you receive HTTP 429.

## 2.Query Dynamic GB traffic usage

`GET /wapi/consume/dynamic/chart/`

```http theme={null}
Authorization: Bearer YOUR_TOKEN
```

<table>
  <colgroup>
    <col width="176" />

    <col width="563" />
  </colgroup>

  <thead>
    <tr>
      <th>**Query parameter**</th>
      <th>**Description**</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`suname`</td>
      <td>Sub-account username; omit or leave empty to query the main account</td>
    </tr>

    <tr>
      <td>`st`</td>
      <td>Start time, Unix seconds</td>
    </tr>

    <tr>
      <td>`et`</td>
      <td>End time, Unix seconds</td>
    </tr>
  </tbody>
</table>

Example: `GET /wapi/consume/dynamic/chart/?suname=sub_account&st=1735689600&et=1735776000`

Accounts that have purchased a Dynamic GB or Advanced Dynamic GB package, or redeemed Dynamic traffic, can use this endpoint.

## 3.Query Premium Dynamic GB traffic usage

`GET /wapi/consume/premium/chart/`

Use the same header, query parameters, and response format as the Dynamic GB usage endpoint. Example: `GET /wapi/consume/premium/chart/?suname=sub_account&st=1735689600&et=1735776000`. Accounts that have purchased a Premium Dynamic GB package can use this endpoint.

Both usage endpoints follow these rules:

* If either `st` or `et` is omitted or not greater than 0, the query covers midnight to now in the account's time zone.
* If `st` equals `et`, the query covers one day from that time. A start time after the end time produces a parameter error.
* results`contains time-ordered data points.`period`identifies the time interval,`timestamp`is its Unix timestamp in seconds, and`total\_traffic\_count\` is traffic used during that interval, in bytes. Intervals without usage return 0.

Example response (values are illustrative):

```json theme={null}
{
  "code": 200,
  "message": "success.",
  "results": [
    {
      "period": "2025-01-01T00:00:00Z",
      "timestamp": 1735689600,
      "total_traffic_count": 1048576
    }
  ]
}
```

## 4.Create redemption codes (CDKs) in batch

`POST /wapi/cdk/create/`

```http theme={null}
Content-Type: application/json
Authorization: Bearer YOUR_TOKEN
```

<table>
  <colgroup>
    <col width="100" />

    <col width="520" />
  </colgroup>

  <thead>
    <tr>
      <th>**Field**</th>
      <th>**Description**</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`cdk_type`</td>
      <td>Required: `1` Dynamic traffic, `2` IP count, `3` Mobile traffic</td>
    </tr>

    <tr>
      <td>`flow`</td>
      <td>Required for types 1 and 3; traffic per code in GB, from 1 to 10000</td>
    </tr>

    <tr>
      <td>`ip`</td>
      <td>Required for type 2; IP count per code, from 1 to 10000</td>
    </tr>

    <tr>
      <td>`day`</td>
      <td>Validity period in days for types 1 and 3</td>
    </tr>

    <tr>
      <td>`num`</td>
      <td>Required; number of codes to create, from 1 to 10000</td>
    </tr>
  </tbody>
</table>

Example for Dynamic traffic codes:

```json theme={null}
{
  "cdk_type": 1,
  "flow": 10,
  "day": 30,
  "num": 2
}
```

On success, `results` lists the generated codes. `Cdk` is the redemption code, `Type` is its type, `Flow` is in bytes, `Ip` is the IP count, and `Days` is the validity period:

```json theme={null}
{
  "code": 200,
  "results": [
    { "Cdk": "EXAMPLE1", "Type": 1, "Flow": 10000000000, "Ip": 0, "Days": 30 }
  ]
}
```

Ensure your account has enough of the corresponding resource. If it does not, the entire batch fails. Do not submit identical creation requests concurrently. This endpoint is rate-limited; retry later if you receive HTTP 429.

## Common errors

| `code` | **Meaning** |
| :-: | :-: |
| `41001` | Invalid query parameters or sub-account not found |
| `41003` | Incorrect account name or password |
| `41005` | Account not eligible for the requested endpoint |
| `41010` | Invalid token (HTTP 403) |
| `40049` | Invalid CDK creation parameters |
| `40052` | CDK creation failed, for example due to insufficient resources |
| `40901` | An identical creation request is already being processed |

Always check `code` in the response: some business errors are returned with HTTP 200.


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