# Get usage

`GET https://my.neuronai.uz/api/v1/usage`

API maʼlumotnomasi › Balans va sarf

Returns your organization's spend and request counts for the last 7, 30 or 90 days, by service and by API key. Reading usage is free.

**Authentication:** `Authorization: Bearer <API key>`, a key with `account:read`.

## Soʻrov parametrlari

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `days` | integer | No | How many days to count, today included. One of `7`, `30`, `90`. Default `30`. |

## Javob (200, `application/json`)

Usage totals grouped by service and by API key.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object | Yes |  |
| `data.period` | object | Yes |  |
| `data.period.days` | integer | Yes |  |
| `data.period.start` | string | Yes |  |
| `data.period.end` | string | Yes |  |
| `data.total` | object | Yes |  |
| `data.total.requests` | integer | Yes |  |
| `data.total.cost` | number | Yes |  |
| `data.total.formatted_cost` | string | Yes |  |
| `data.total.currency` | string | Yes |  |
| `data.by_service` | object[] | Yes | One row per service used in the window, the costliest first: its code, such as `llm`, its name, and its requests and spend in credits. |
| `data.by_service[].service` | string | Yes |  |
| `data.by_service[].label` | string | Yes |  |
| `data.by_service[].requests` | integer | Yes |  |
| `data.by_service[].cost` | number | Yes |  |
| `data.by_key` | object[] | Yes | One row per API key used in the window, the costliest first. `id` is the key's `id`, as the API keys endpoints show it, or `null` for requests made from the dashboard. |
| `data.by_key[].id` | string \| null | Yes |  |
| `data.by_key[].name` | string | Yes |  |
| `data.by_key[].requests` | integer | Yes |  |
| `data.by_key[].cost` | number | Yes |  |
| `request_id` | string | Yes |  |

```json
{
  "data": {
    "period": {
      "days": 30,
      "start": "2026-11-01",
      "end": "2026-11-17"
    },
    "total": {
      "requests": 128,
      "cost": 12.6,
      "formatted_cost": "string",
      "currency": "credits"
    },
    "by_service": [
      {
        "service": "tts",
        "label": "string",
        "requests": 128,
        "cost": 12.6
      }
    ],
    "by_key": [
      {
        "id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41",
        "name": "Aziza",
        "requests": 128,
        "cost": 12.6
      }
    ]
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

### Sarlavhalar

| Header | Type | Description |
| --- | --- | --- |
| `X-Request-Id` | string | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
| `X-RateLimit-Limit` | integer | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
| `X-RateLimit-Remaining` | integer | How many of them are left this minute. |

## Xatolar

Every error has the same JSON shape:

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "The request is malformed or failed validation.",
    "param": null
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

| Status | Meaning |
| --- | --- |
| 401 | The API key is missing or not recognized (`invalid_api_key`), revoked (`api_key_revoked`), disabled (`api_key_disabled`) or expired (`api_key_expired`). |
| 403 | The key lacks the permission this endpoint needs (`insufficient_permissions`), or the client IP is not in its allowlist (`ip_not_allowed`). |
| 422 | The request failed validation (`invalid_request`). `error.fields` names each invalid field. |
| 429 | A rate or concurrency limit was reached (`rate_limit_exceeded`, `concurrency_limit_exceeded`). Retry after `Retry-After` seconds. |
| default | Any other error, in the same shape, such as `server_error` (500) or `service_unavailable` (503). |

## Examples

### cURL

```bash
# Your balance, in credits
curl "https://my.neuronai.uz/api/v1/balance" \
  -H "Authorization: Bearer <your-api-key>"

# Spend and request counts over the last 30 days
curl "https://my.neuronai.uz/api/v1/usage?days=30" \
  -H "Authorization: Bearer <your-api-key>"
```

### TypeScript SDK

```typescript
import {NeuronAI} from "@naiuz/sdk";

const client = new NeuronAI();

const usage = await client.account.usage({days: 30});

console.log(usage.total, usage.by_service);
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

usage = client.account.usage(days=30)

print(usage.total, usage.by_service)
```

### PHP SDK

```php
$client = new \Naiuz\NeuronAI();

$usage = $client->account->usage(['days' => 30]);

print_r($usage->total);
print_r($usage->by_service);
```

### JavaScript

```javascript
const response = await fetch('https://my.neuronai.uz/api/v1/usage?days=30', {
  headers: { Authorization: 'Bearer <your-api-key>' },
});

const { data } = await response.json();
const { total, by_service: byService } = data;
```

---

Source: https://docs.neuronai.uz/uz/api/reference/account/retrieve-usage
