# GET /v1/balance

Lấy số dư

Số dư hiện tại của publisher: `available` là số tiền có thể yêu cầu rút, `pending` là doanh thu ước tính (các ngày AGIMone chưa chốt; chưa rút được tới khi đã chốt), `held` là tổng khoản giữ đang hoạt động (đã trừ khỏi `available`), `requested` là số tiền trong các yêu cầu rút đang mở, `paid_total` là tổng đã trả, `min_payout` là mức rút tối thiểu. Mọi số tiền là chuỗi tiền tệ. Cùng số liệu với trường `balance` của GET /v1/earnings. Cần quyền `publisher:read` (khoá API hoặc phiên web). Tầng giới hạn tốc độ: `read`.

- Quyền cần có: `publisher:read`
- Giới hạn tốc độ: `read` — 120 yêu cầu mỗi cửa sổ 60 giây cho mỗi API key hoặc phiên web

## Tham số

Không có tham số.

## Phản hồi

```
{ available: string; held: string; min_payout: string; paid_total: string; pending: string; requested: string }
```

## Lỗi

Các route có giới hạn tốc độ trả `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset` (số giây tới hết cửa sổ); phản hồi 429 có thêm `Retry-After`. Header có thể vắng khi bộ giới hạn tạm thời không sẵn sàng (khi đó yêu cầu vẫn được cho qua).

| Mã | Ý nghĩa |
|---|---|
| 401 | Thiếu, sai hoặc đã thu hồi API key. |
| 403 | Key thiếu quyền cần có, hoặc thao tác không được phép với tác nhân này. |
| 429 | Vượt giới hạn tốc độ; chờ `Retry-After` giây. |

## Ví dụ

### cURL

```bash
#!/usr/bin/env bash
# GET /v1/balance: current balance (pending, available, requested, paid_total, min_payout).
# Needs: AGIMONE_API_KEY (create one at https://app.agimone.com/app/account/api-keys). Optional: AGIMONE_API_BASE.
set -euo pipefail
BASE="${AGIMONE_API_BASE:-https://app.agimone.com}"
curl -fsS -H "Authorization: Bearer $AGIMONE_API_KEY" "$BASE/v1/balance"
echo
```

### Node.js

```js
// GET /v1/balance: current balance (pending, available, requested, paid_total, min_payout). Node 18+, no dependencies.
// Needs: AGIMONE_API_KEY (create one at https://app.agimone.com/app/account/api-keys). Optional: AGIMONE_API_BASE.
const base = process.env.AGIMONE_API_BASE ?? 'https://app.agimone.com';

const res = await fetch(`${base}/v1/balance`, {
  headers: { Authorization: `Bearer ${process.env.AGIMONE_API_KEY}` },
});
if (!res.ok) {
  console.error(`HTTP ${res.status}: ${await res.text()}`);
  process.exit(1);
}
console.log(JSON.stringify(await res.json()));
```

### PHP

```php
<?php
// GET /v1/balance: current balance (pending, available, requested, paid_total, min_payout). PHP 8 with the curl extension, no other dependencies.
// Needs: AGIMONE_API_KEY (create one at https://app.agimone.com/app/account/api-keys). Optional: AGIMONE_API_BASE.
$base = getenv('AGIMONE_API_BASE') ?: 'https://app.agimone.com';

$ch = curl_init("$base/v1/balance");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('AGIMONE_API_KEY')],
    CURLOPT_TIMEOUT => 15,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
    fwrite(STDERR, "HTTP $status: " . ($body === false ? curl_error($ch) : $body) . "\n");
    exit(1);
}
curl_close($ch);
echo trim($body), "\n";
```

### Python

```python
# GET /v1/balance: current balance (pending, available, requested, paid_total, min_payout). Python 3.8+, standard library only.
# Needs: AGIMONE_API_KEY (create one at https://app.agimone.com/app/account/api-keys). Optional: AGIMONE_API_BASE.
import json
import os
import sys
import urllib.error
import urllib.request

base = os.environ.get("AGIMONE_API_BASE", "https://app.agimone.com")
req = urllib.request.Request(
    f"{base}/v1/balance",
    headers={"Authorization": f"Bearer {os.environ['AGIMONE_API_KEY']}"},
)
try:
    with urllib.request.urlopen(req, timeout=15) as res:
        print(json.dumps(json.load(res)))
except urllib.error.HTTPError as e:
    print(f"HTTP {e.code}: {e.read().decode()}", file=sys.stderr)
    sys.exit(1)
```

Tài liệu HTML: https://agimone.com/vi/developers/api/#get-balance
API 2026-10
