# 查询当前账户

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

查询当前用户可访问的 Billing 账户及 Credit 余额。首次查询时，系统会按当前用户信息准备 Billing 账户。

```text
GET https://billing.moi.matrixorigin.cn/api/v1/billing/accounts/current
```

## 调用前准备

准备有效的[个人访问令牌](../../../../../guides/genesis/api-keys.md#创建和管理个人访问令牌)。

## 请求示例

将示例中的 `$MOI_PERSONAL_ACCESS_TOKEN` 替换为个人访问令牌。

```bash
curl -X GET \
  "https://billing.moi.matrixorigin.cn/api/v1/billing/accounts/current" \
  -H "X-API-Key: $MOI_PERSONAL_ACCESS_TOKEN"
```

## 成功响应

请求成功时返回 HTTP `200` 和当前用户可访问的 Billing 账户及其 Credit 余额。

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} 响应示例

```json
{
  "items": [
    {
      "billing_account_id": "billing_account_example",
      "owner_type": "uc_account",
      "owner_id": "owner_example",
      "display_name": "Example account",
      "region": "cn",
      "status": "active",
      "default_currency": "CNY",
      "credit_balance": "100.000000000000",
      "credit_cash_balance": "80.000000000000",
      "credit_grant_balance": "20.000000000000",
      "credit_reserved": "10.000000000000",
      "credit_available": "90.000000000000",
      "credit_overdraft_balance": "0.000000000000",
      "risk_level": "normal",
      "created_at": 1788739200,
      "updated_at": 1788739200
    }
  ],
  "total": 1
}
```

:::::
:::::{tab-item} 字段说明

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `items` | array of object | 本次返回的记录。 |
| `items[].billing_account_id` | string | Billing 账户 ID。 |
| `items[].owner_type` | string | 账户归属主体类型。 |
| `items[].owner_id` | string | 账户归属主体 ID。 |
| `items[].display_name` | string | 账户显示名称。 |
| `items[].region` | string | 账户地区。 |
| `items[].status` | string | 账户状态。 |
| `items[].default_currency` | string | 账户默认支付币种。 |
| `items[].credit_balance` | string | Credit 余额。 |
| `items[].credit_cash_balance` | string | 充值 Credit 余额。 |
| `items[].credit_grant_balance` | string | 赠送 Credit 余额。 |
| `items[].credit_reserved` | string | 已预留的 Credit。 |
| `items[].credit_available` | string | 可用 Credit。 |
| `items[].credit_overdraft_balance` | string | 透支钱包余额。 |
| `items[].risk_level` | string | 账户风险等级。 |
| `items[].status_reason` | string | 账户状态原因，存在时返回。 |
| `items[].suspended_at` | integer | 停用时间，Unix 秒；存在时返回。 |
| `items[].closed_at` | integer | 关闭时间，Unix 秒；存在时返回。 |
| `items[].created_at` | integer | 创建时间，Unix 秒。 |
| `items[].updated_at` | integer | 更新时间，Unix 秒。 |
| `total` | integer | 返回的总记录数。 |

字段路径中的 `[]` 表示数组中的每一项。例如，`items[].billing_account_id` 表示数组中每一项的对应字段。

:::::
::::::
:::::::

## 错误响应

缺少认证信息时返回 HTTP `401`，请提供有效的个人访问令牌。

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} 响应示例

```json
{
  "code": "unauthenticated",
  "message": "missing bearer token",
  "error": "missing bearer token"
}
```

:::::
:::::{tab-item} 字段说明

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `code` | string | 错误代码。 |
| `message` | string | 错误说明。 |
| `error` | string | 兼容错误说明，与 message 内容相同。 |

:::::
::::::
:::::::

(billing-account-selection)=
## 选择账户

从 `items` 中选择账户，保存该项的 `billing_account_id`，用于按账户查询。

使用该账户 ID [查询账户概览](overview.md)或[查询计费设置](settings.md)。
