# AIOZ Stream — Payments

SDK package: @aiozstream/nodejs-client
Note: Payments API is not yet in the SDK — use fetch with Bearer token (JWT only).

## Setup

```typescript
// Payments require JWT authentication, not API keys
const HEADERS = {
  'Authorization': `Bearer ${process.env.AIOZ_JWT_TOKEN}`,
  'Content-Type': 'application/json'
}
const BASE = 'https://api.aiozstream.network/api'
```

---

## Get User Usage

GET https://api.aiozstream.network/api/payment/usage

Returns storage, delivery, and transcoding totals for a time period.

```typescript
async function getUsage(from: number, to: number) {
  const res = await fetch(
    `${BASE}/payment/usage?from=${from}&to=${to}`,
    { headers: HEADERS }
  )
  return res.json()
}

const now = Math.floor(Date.now() / 1000)
const thirtyDaysAgo = now - 30 * 24 * 60 * 60

const usage = await getUsage(thirtyDaysAgo, now)
// usage.data.storage      — bytes used
// usage.data.storage_cost — cost string (preserves precision)
// usage.data.delivery     — bytes delivered
// usage.data.delivery_cost
// usage.data.transcode    — seconds transcoded
// usage.data.transcode_cost
```

---

## Get Top-Ups

GET https://api.aiozstream.network/api/payment/top_ups

Returns AIOZ token top-up transactions.

```typescript
async function getTopUps(limit = 25, offset = 0) {
  const res = await fetch(
    `${BASE}/payment/top_ups?limit=${limit}&offset=${offset}&orderBy=desc&sortBy=created_at`,
    { headers: HEADERS }
  )
  return res.json()
}

const topUps = await getTopUps()
// topUps.data.total
// topUps.data.top_ups: [{
//   transaction_id, from (wallet address), status, created_at, credit
// }]
```

---

## Get Billings

GET https://api.aiozstream.network/api/payment/billings

Returns daily billing records.

```typescript
async function getBillings(limit = 25, offset = 0) {
  const res = await fetch(
    `${BASE}/payment/billings?limit=${limit}&offset=${offset}&orderBy=desc`,
    { headers: HEADERS }
  )
  return res.json()
}

const billings = await getBillings()
// billings.data.total
// billings.data.billings: [{
//   storage, delivery, transcode,
//   storage_cost, delivery_cost, transcode_cost,
//   created_at
// }]
```
