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

# GET /api/user/self

> Retrieve the current user's wallet, credit, test voucher, and subscription quota summary.

`/api/user/self` returns the available quotas for the currently authenticated user. It only returns balance data. To retrieve the user's full profile, including their name, email, role, permissions, and settings, use `GET /api/user/self/all`.

## Request

| Item                | Value                                  |
| ------------------- | -------------------------------------- |
| Method              | `GET`                                  |
| Path                | `/api/user/self`                       |
| Production endpoint | `https://www.anyfast.ai/api/user/self` |
| Request body        | None                                   |
| Query parameters    | None                                   |

## Authentication

The endpoint only allows access to the currently authenticated user's balance. You can authenticate with a system access token or a login session.

<Warning>
  A system access token is not an `sk-...` API key used for model requests. `New-Api-User` must be a numeric user ID that matches the user associated with the token or session.
</Warning>

<CodeGroup>
  ```bash System access token theme={null}
  curl --location 'https://www.anyfast.ai/api/user/self' \
    --header 'Authorization: Bearer <SYSTEM_ACCESS_TOKEN>' \
    --header 'New-Api-User: <USER_ID>' \
    --header 'Accept: application/json'
  ```

  ```bash Login session theme={null}
  curl --location 'https://www.anyfast.ai/api/user/self' \
    --header 'Cookie: anyfast_session=<SESSION_COOKIE>' \
    --header 'New-Api-User: <USER_ID>' \
    --header 'Accept: application/json'
  ```
</CodeGroup>

Neither regular users nor administrators can retrieve another user's data by changing `New-Api-User`.

## Successful response

```json theme={null}
{
  "data": {
    "quota": 12747995,
    "details": {
      "wallet_quota": 500000,
      "credit_quota": 12247995,
      "test_voucher_quota": 0,
      "subscription_quota": 0,
      "subscription_unlimited": false
    }
  },
  "message": "",
  "success": true
}
```

## Response fields

| Field                                 | Type            |   Required | Description                                                                            |
| ------------------------------------- | --------------- | ---------: | -------------------------------------------------------------------------------------- |
| `success`                             | boolean         |        Yes | Whether the business operation succeeded.                                              |
| `message`                             | string          |        Yes | Response message. Usually empty on success.                                            |
| `data`                                | object          | On success | The current user's balance summary. Partial balance data is not returned on failure.   |
| `data.quota`                          | integer (int64) |        Yes | The sum of the wallet balance and remaining active credit.                             |
| `data.details`                        | object          |        Yes | Separate balances for each funding source.                                             |
| `data.details.wallet_quota`           | integer (int64) |        Yes | The user's current wallet balance.                                                     |
| `data.details.credit_quota`           | integer (int64) |        Yes | The remaining amount of active credit, not the total or used amount.                   |
| `data.details.test_voucher_quota`     | integer (int64) |        Yes | The remaining total for active, unexpired, non-voided, and non-depleted test vouchers. |
| `data.details.subscription_quota`     | integer (int64) |        Yes | The remaining total for active, limited subscriptions.                                 |
| `data.details.subscription_unlimited` | boolean         |        Yes | Whether the user has an active unlimited subscription.                                 |

All monetary fields use the platform's native integer `quota` unit. Fields remain present when their value is `0`.

## Calculation

`data.quota` only includes the wallet balance and remaining active credit:

```text theme={null}
data.quota = wallet_quota + credit_quota
```

For the example above, `500000 + 12247995 = 12747995`.

The following fields are not included in `data.quota`:

* `test_voucher_quota`
* `subscription_quota`
* `subscription_unlimited`

Therefore, `data.quota` is not the sum of every funding source.

## Quota definitions

### Wallet balance

`wallet_quota` is the user's current wallet balance. A subsequent request returns the latest value after a top-up, an administrator adjustment, or wallet usage completes.

### Credit quota

`credit_quota` only includes the remaining amount of credit with an `active` status:

```text theme={null}
credit_quota = amount_total - amount_used
```

Disabled or reclaimed credit is not included.

### Test voucher quota

`test_voucher_quota` only includes vouchers that meet all of the following conditions:

* The effective time has started.
* The expiration time has not passed.
* The voucher is available.
* The remaining quota is greater than `0`.

Model restrictions do not affect the displayed voucher balance, but they do affect whether the voucher can be used for a specific model request.

### Subscription quota

`subscription_quota` is the remaining quota for limited subscriptions. Unlimited subscriptions are represented separately by `subscription_unlimited: true`; no special number or string is written to `data.quota`.

## Currency conversion

Clients should calculate with the original `quota` values and should not hard-code a USD conversion rate.

The current production environment is configured as follows:

```text theme={null}
500000 quota = $1
```

With the current production conversion, the example response represents:

| Funding source     |    quota | Production value |
| ------------------ | -------: | ---------------: |
| Wallet             |   500000 |       \$1.000000 |
| Available credit   | 12247995 |      \$24.495990 |
| Wallet plus credit | 12747995 |      \$25.495990 |

Conversion settings can differ between deployments. The current production rate is not a fixed API contract.

## Error responses

Authentication failures do not include balance or full-profile data. For example, an invalid token may return:

```json theme={null}
{
  "message": "无权进行此操作，access token 无效",
  "success": false
}
```

A `New-Api-User` value that does not match the authenticated user may return:

```json theme={null}
{
  "success": false,
  "message": "无权进行此操作，New-Api-User 与登录用户不匹配"
}
```

A session that does not belong to the current site typically returns HTTP `403`. If a server-side query fails, the response indicates failure and does not include a `data` object assembled from only some funding sources.

<Warning>
  Some authentication failures can return HTTP `200` with `success: false` in the response body. Clients must check the HTTP status, `success`, and `message` together.
</Warning>

<script src="/public/feedback.js" />
