# Platform API Reference

The Dwellir CLI wraps Dwellir's HTTP Platform API. Every account operation the CLI performs is available as a standard JSON HTTP endpoint authenticated with the same scoped, revocable CLI token.

Use the Platform API directly when you want to pull usage history into a billing pipeline, automate key rotation, or monitor errors from a service without installing the CLI binary.

## Base URL and headers

All Platform API requests go to:

```text
https://dashboard.dwellir.com/marly-api
```

Include these headers on authenticated requests:

```text
Authorization: Bearer <CLI_TOKEN>
Accept: application/json
Content-Type: application/json
```

`Content-Type: application/json` is required on `POST` and `PATCH` requests that send a JSON body.

Platform API requests use a **CLI token** in the `Authorization: Bearer` header. Blockchain RPC requests to `api-{network}.n.dwellir.com` use an **RPC API key** in `X-Api-Key` or the URL path. See [API Authentication](https://www.dwellir.com/docs/getting-started/authentication) for RPC endpoints.

## Authentication

### Create a CLI token

Create a CLI token in one of two ways:

1. **Dashboard**: Open [dashboard.dwellir.com](https://dashboard.dwellir.com), open [API keys > CLI tokens](https://dashboard.dwellir.com/api-keys?tab=cli-tokens), click **Create token**, choose a scope, and copy the value.
2. **CLI**: Run `dwellir auth login` once in a browser, then print the token with `dwellir auth token`.

Store the token in an environment variable or secret manager:

```bash
export DWELLIR_TOKEN="<YOUR_CLI_TOKEN>"
```

### Token scopes

CLI tokens carry a scope that controls which Platform API routes they can call:

| Scope        | Permissions                                                                                              | Recommended use                                  |
| ------------ | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| `read`       | Read usage analytics, error logs, endpoints, API keys, IP whitelists, and account details                | Headless usage polling, BI pipelines, monitoring |
| `read-write` | Everything in `read`, plus create, update, rotate, and delete API keys and IP whitelists                 | CI/CD provisioning and key rotation              |
| `spend`      | Everything in `read-write`, plus billing purchases (when the token owner also holds billing permissions) | Automated add-on provisioning                    |
| `admin`      | Full CLI token privilege level                                                                           | Administrative automation                        |

Calling a write route with a `read` token returns HTTP `403` with a structured `detail` object:

```json
{
  "detail": {
    "code": "cli_token_scope_too_low",
    "message": "CLI token scope 'read' is below the required 'read-write' scope",
    "requiredScope": "read-write",
    "tokenScope": "read"
  }
}
```

### Token expiry and automatic refresh

CLI tokens expire after 90 days. When a valid token within 7 days of expiry makes an authenticated request, the API extends its expiry by 90 days and returns the new UTC timestamp in the `X-Dwellir-Refreshed-Token-Expiry` response header. The token string does not change.

### Rate limits

Usage analytics and request source IP endpoints enforce a per-caller token bucket (default 5 requests per second, burst 10). Exceeding the limit returns HTTP `429 Too Many Requests` with a `Retry-After` header in seconds.

## Usage analytics

Pull billing-cycle totals, time-bucketed usage by chain and RPC method, RPS statistics, and rate-limited request counts. All usage endpoints accept a `read` token.

### Current billing cycle summary

`GET /v4/organization/analytics/monthly_summary`

Returns total requests and responses for the current billing cycle. `dwellir usage summary` starts from this call. It also reads the billing cycle dates from `GET /v4/organization/information/outseta` and the rate-limited count from `POST /v4/organization/analytics/rps`.

```bash
curl -sS https://dashboard.dwellir.com/marly-api/v4/organization/analytics/monthly_summary \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Accept: application/json"
```

Response:

```json
{
  "total_requests": 14820410,
  "total_responses": 14819204
}
```

### Usage history by chain, method, and key

`POST /v4/organization/analytics`

Returns time-bucketed request and response counts grouped by timestamp, endpoint domain (chain), RPC method, and API key. `dwellir usage history --json` returns these rows. `dwellir usage methods` and `dwellir usage rps` aggregate them on the client.

**Request body:**

| Field             | Type                          | Default         | Description                                                                                               |
| ----------------- | ----------------------------- | --------------- | --------------------------------------------------------------------------------------------------------- |
| `interval`        | `"minute" \| "hour" \| "day"` | `"hour"`        | Aggregation bucket size                                                                                   |
| `start_time`      | string (ISO 8601)             | Backend default | Window start timestamp, inclusive (UTC assumed if no offset)                                              |
| `end_time`        | string (ISO 8601)             | Backend default | Window end timestamp, exclusive                                                                           |
| `since`           | string (ISO 8601)             | `null`          | Exclusive lower bound for delta polling (second granularity). Takes precedence if later than `start_time` |
| `filter.api_keys` | `string[]`                    | `null`          | Filter to specific full API key UUIDs belonging to your organization                                      |
| `filter.domains`  | `string[]`                    | `null`          | Filter to specific endpoint FQDNs, such as `api-ethereum-mainnet.n.dwellir.com`                           |
| `limit`           | integer                       | `1000`          | Maximum rows per page (1 to 10,000)                                                                       |
| `offset`          | integer                       | `0`             | Row offset for pagination                                                                                 |

```bash
curl -sS -X POST https://dashboard.dwellir.com/marly-api/v4/organization/analytics \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "interval": "day",
    "start_time": "2026-04-01T00:00:00Z",
    "end_time": "2026-04-08T00:00:00Z",
    "filter": {
      "domains": ["api-ethereum-mainnet.n.dwellir.com"]
    },
    "limit": 1000,
    "offset": 0
  }'
```

Response:

```json
[
  {
    "start_time": "2026-04-01T00:00:00Z",
    "domain": "api-ethereum-mainnet.n.dwellir.com",
    "method": "eth_call",
    "requests": 412890,
    "responses": 412845,
    "api_key": "d8d3a120-0000-4000-8000-00000000eef9",
    "api_key_name": "production"
  }
]
```

**Pagination and delta headers:**

Each response includes two headers to help incremental polling and pagination:

- `X-Analytics-Has-More`: `"true"` when the number of returned rows reached `limit`. Increment `offset` by `limit` to fetch the next page.
- `X-Analytics-Max-Timestamp`: ISO 8601 UTC timestamp of the newest row returned. Pass this value as `since` on your next scheduled poll to fetch only newer rows.

### Requests per second (RPS)

`POST /v4/organization/analytics/rps`

Returns average RPS, peak RPS, peak wall-second timestamp, and rate-limited request count for a time window. Defaults to the start of the current UTC month through now when timestamps are omitted. Accepts `interval`, `start_time`, `end_time`, `since`, and `filter` (`api_keys`, `domains`). `dwellir usage summary` uses this endpoint for its rate-limited count. `dwellir usage rps` does not call it: the CLI divides each `POST /v4/organization/analytics` bucket by the bucket length.

```bash
curl -sS -X POST https://dashboard.dwellir.com/marly-api/v4/organization/analytics/rps \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "interval": "hour",
    "start_time": "2026-04-07T00:00:00Z",
    "end_time": "2026-04-08T00:00:00Z"
  }'
```

Response:

```json
{
  "type": "analyticsrps",
  "version": "2",
  "rps": 42.7,
  "peak_rps": 185.0,
  "limited_requests": 12.0,
  "max_wall_second": "2026-04-07T14:22:09Z",
  "avg_rps_at_peak": 161.4
}
```

### Rate-limited requests

`POST /v4/organization/analytics/rate-limited`

Returns time-bucketed counts of rate-limited requests per endpoint domain and API key. Accepts the same request body and returns the same `X-Analytics-Has-More` and `X-Analytics-Max-Timestamp` headers as `POST /v4/organization/analytics`.

Response item shape:

```json
{
  "start_time": "2026-04-07T14:00:00Z",
  "domain": "api-ethereum-mainnet.n.dwellir.com",
  "requests": 12,
  "api_key": "d8d3a120-0000-4000-8000-00000000eef9",
  "api_key_name": "production"
}
```

## Error logs

Query failed RPC requests, status-code breakdowns, and error facets. All error log endpoints accept a `read` token.

Lookback retention depends on your plan:

- **Free / Starter**: 24 hours
- **Developer / Growth**: 7 days
- **Scale / Custom**: 90 days

If `start_time` and `end_time` are omitted, the API queries the last 24 hours. Requests earlier than your plan's lookback window are clamped to the plan limit.

### List error logs

`POST /v4/organization/logs/errors`

Returns cursor-paginated error log records. Equivalent to `dwellir logs errors --json`.

**Request body:**

| Field        | Type              | Default  | Description                                                                                                                  |
| ------------ | ----------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `start_time` | string (ISO 8601) | 24h ago  | Start of lookback window                                                                                                     |
| `end_time`   | string (ISO 8601) | now      | End of lookback window                                                                                                       |
| `page_size`  | integer           | `100`    | Results per page (1 to 200)                                                                                                  |
| `cursor`     | string            | `null`   | Pagination cursor from `next_cursor` or `prev_cursor`                                                                        |
| `order`      | `"desc" \| "asc"` | `"desc"` | Sort order by timestamp                                                                                                      |
| `filter`     | object            | `null`   | Optional filters: `api_keys`, `fqdns`, `status_codes`, `error_types`, `http_methods`, `rpc_methods`, `origins`, `request_id` |

```bash
curl -sS -X POST https://dashboard.dwellir.com/marly-api/v4/organization/logs/errors \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "page_size": 25,
    "order": "desc",
    "filter": {
      "status_codes": [429],
      "fqdns": ["api-ethereum-mainnet.n.dwellir.com"]
    }
  }'
```

Response fields include `items` (each row contains `timestamp`, `request_id`, `api_key`, `fqdn`, `response_status_code`, `response_status_label`, `request_rpc_methods`, `error_type`, `error_message`, `backend_latency_ms`, `total_latency_ms`, and `occurrence_count`), `next_cursor`, `prev_cursor`, and `has_more`.

To look up a single error log by request ID, call `GET /v4/organization/logs/errors/{request_id}`.

### Error stats and facets

These endpoints accept the same `start_time`, `end_time`, and `filter` fields as `/v4/organization/logs/errors`:

- `POST /v4/organization/logs/error-classes`: Error counts grouped by HTTP status code (`items`) and error type (`error_types`). Equivalent to `dwellir logs stats --json`.
- `POST /v4/organization/logs/error-facets`: Aggregated counts across `fqdns`, `rpc_methods`, `origins`, and `api_keys`. Accepts an optional `limits` object (`{ fqdns, rpc_methods, origins, api_keys }`). Equivalent to `dwellir logs facets --json`.
- `POST /v4/organization/logs/summary`: Returns window totals `{ successful_responses, total_errors, rate_limited }`.

## API keys

Manage organization RPC API keys programmatically. Reading keys requires `read` scope; creating, updating, rotating, and deleting keys require `read-write` scope.

| Method   | Path                                        | Scope        | Description                                    |
| -------- | ------------------------------------------- | ------------ | ---------------------------------------------- |
| `GET`    | `/v4/organization/apikeys`                  | `read`       | List all active API keys                       |
| `POST`   | `/v4/organization/apikeys`                  | `read-write` | Create a new API key (`201 Created`)           |
| `POST`   | `/v4/organization/apikeys/{api_key}`        | `read-write` | Update a key's name, enabled flag, and quotas  |
| `POST`   | `/v4/organization/apikeys/{api_key}/rotate` | `read-write` | Replace the key value immediately              |
| `DELETE` | `/v4/organization/apikeys/{api_key}`        | `read-write` | Permanently delete an API key (`204` or `202`) |

### Create an API key

```bash
curl -sS -X POST https://dashboard.dwellir.com/marly-api/v4/organization/apikeys \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "ci-indexer",
    "daily_quota": 100000,
    "monthly_quota": 3000000
  }'
```

Omit `daily_quota` or `monthly_quota` (or pass `null`) for unlimited quotas.

### Update an API key

`POST /v4/organization/apikeys/{api_key}` replaces all four editable fields. Read the current key first and send every field you want to keep:

```bash
curl -sS -X POST "https://dashboard.dwellir.com/marly-api/v4/organization/apikeys/${RPC_API_KEY}" \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "ci-indexer",
    "enabled": true,
    "daily_quota": 250000,
    "monthly_quota": 3000000
  }'
```

### Rotate or delete an API key

- **Rotate** (`POST /v4/organization/apikeys/{api_key}/rotate`, empty body): Issues a new key value while preserving the key ID, name, quotas, enabled state, and assigned IP whitelists. The old value stops working immediately. Do not automatically retry on timeout because the rotation may already have completed.
- **Delete** (`DELETE /v4/organization/apikeys/{api_key}`): Returns `204 No Content` when removed immediately, or `202 Accepted` with `{"detail": "API key deleted; propagation pending", "cleanup_pending": true}` while edge invalidation finishes.

## IP whitelists and source IPs

Manage IP allowlists for your organization's API keys. See [IP Whitelisting](https://www.dwellir.com/docs/getting-started/ip-whitelisting) for how enforcement behaves on RPC traffic.

| Method   | Path                                                               | Scope        | Description                                                                    |
| -------- | ------------------------------------------------------------------ | ------------ | ------------------------------------------------------------------------------ |
| `GET`    | `/v4/organization/ip-whitelists`                                   | `read`       | List IP whitelists, CIDR entries, and assigned keys                            |
| `POST`   | `/v4/organization/ip-whitelists`                                   | `read-write` | Create an IP whitelist (`201 Created`)                                         |
| `PATCH`  | `/v4/organization/ip-whitelists/{whitelist_id}`                    | `read-write` | Update fields on an existing whitelist                                         |
| `DELETE` | `/v4/organization/ip-whitelists/{whitelist_id}`                    | `read-write` | Delete a whitelist (`204 No Content`)                                          |
| `POST`   | `/v4/organization/ip-whitelists/{whitelist_id}/api-keys/{api_key}` | `read-write` | Assign a whitelist to an API key                                               |
| `DELETE` | `/v4/organization/ip-whitelists/{whitelist_id}/api-keys/{api_key}` | `read-write` | Remove a manual whitelist assignment                                           |
| `GET`    | `/v4/organization/request-source-ips`                              | `read`       | List recent source IPs seen on your traffic (`days` 1 to 30, `limit` 1 to 250) |

Create an IP whitelist:

```bash
curl -sS -X POST https://dashboard.dwellir.com/marly-api/v4/organization/ip-whitelists \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "eu-egress",
    "description": "Production NAT gateways",
    "entries": ["203.0.113.10/32", "198.51.100.42/32"],
    "apply_to_all_api_keys": false,
    "enabled": true
  }'
```

`PATCH /v4/organization/ip-whitelists/{whitelist_id}` updates only the fields you include. It rejects `null` for `name`, `entries`, `apply_to_all_api_keys`, and `enabled`.

## Endpoints and network catalog

| Method | Path                  | Auth          | Description                                                                                                                     |
| ------ | --------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `GET`  | `/v3/chains`          | `read` token  | Authenticated catalog of chains, networks, and node URLs (`https`, `wss`, `grpc`, `node_type`) used by `dwellir endpoints list` |
| `GET`  | `/v3/networks`        | None (public) | Public network catalog listing one entry per chain slug                                                                         |
| `GET`  | `/v3/networks/{slug}` | None (public) | Public chain detail by slug or EVM chain ID (`ethereum`, `1`, or `0x1`)                                                         |

```bash
curl -sS https://dashboard.dwellir.com/marly-api/v3/chains \
  -H "Authorization: Bearer ${DWELLIR_TOKEN}" \
  -H "Accept: application/json"
```

## Account and subscription

All account read endpoints accept a `read` token.

| Method | Path                                            | Scope  | Description                                                                                                                            |
| ------ | ----------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| `GET`  | `/v4/user`                                      | `read` | Authenticated user profile (`id`, `name`, `email`, `is_verified`)                                                                      |
| `GET`  | `/v4/organization/information/outseta`          | `read` | Organization info, `usageLimits`, `currentSubscription` billing cycle dates, and active add-ons                                        |
| `GET`  | `/v3/user/subscription`                         | `read` | Active subscription plan limits (`name`, `rate_limit`, `burst_limit`, `daily_quota`, `monthly_quota`, `api_keys_limit`)                |
| `GET`  | `/v4/organization/information/outseta/discount` | `read` | Current subscription discount (`applied`, `type`, `percentage` or `flatAmount`, `meta.applyToAddOns`). Apply it when you compute costs |

## CLI to Platform API quick reference

| CLI command                                  | HTTP method and path                                                                                                                                                | Min scope    |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| `dwellir usage summary`                      | `GET /v4/organization/analytics/monthly_summary`, `GET /v4/organization/information/outseta`, and `POST /v4/organization/analytics/rps`                             | `read`       |
| `dwellir usage history`                      | `POST /v4/organization/analytics`                                                                                                                                   | `read`       |
| `dwellir usage methods` / `rps`              | `POST /v4/organization/analytics`, aggregated by the CLI                                                                                                            | `read`       |
| `dwellir usage costs`                        | `GET /v3/user/subscription`, `GET /v4/organization/information/outseta`, `GET /v4/organization/information/outseta/discount`, and `POST /v4/organization/analytics` | `read`       |
| `dwellir logs errors`                        | `POST /v4/organization/logs/errors`                                                                                                                                 | `read`       |
| `dwellir logs stats`                         | `POST /v4/organization/logs/error-classes`                                                                                                                          | `read`       |
| `dwellir logs facets`                        | `POST /v4/organization/logs/error-facets`                                                                                                                           | `read`       |
| `dwellir keys list`                          | `GET /v4/organization/apikeys`                                                                                                                                      | `read`       |
| `dwellir keys create`                        | `POST /v4/organization/apikeys`                                                                                                                                     | `read-write` |
| `dwellir keys update` / `enable` / `disable` | `POST /v4/organization/apikeys/{api_key}`                                                                                                                           | `read-write` |
| `dwellir keys rotate`                        | `POST /v4/organization/apikeys/{api_key}/rotate`                                                                                                                    | `read-write` |
| `dwellir keys delete`                        | `DELETE /v4/organization/apikeys/{api_key}`                                                                                                                         | `read-write` |
| `dwellir endpoints list`                     | `GET /v3/chains`                                                                                                                                                    | `read`       |
| `dwellir account info`                       | `GET /v4/organization/information/outseta`                                                                                                                          | `read`       |
| `dwellir account subscription`               | `GET /v3/user/subscription`                                                                                                                                         | `read`       |

## Error responses

Non-2xx responses return JSON with a `detail` field (either a string message or a structured object such as `cli_token_scope_too_low`).

| HTTP status                | Common cause                                                                                                      |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `400 Bad Request`          | Invalid pagination cursor or filter referencing an API key outside your organization                              |
| `401 Unauthorized`         | Missing `Authorization: Bearer` header, malformed token, expired token, or revoked token                          |
| `403 Forbidden`            | CLI token scope is too low for the route, or missing organization membership                                      |
| `404 Not Found`            | Unknown API key, whitelist ID, request ID, or network slug                                                        |
| `422 Unprocessable Entity` | Request JSON failed schema validation (invalid ISO 8601 timestamp, out-of-range limit, or missing required field) |
| `429 Too Many Requests`    | Platform API rate limit exceeded. Wait for the duration in `Retry-After` before retrying                          |

## Next steps

- [Platform API overview](https://www.dwellir.com/docs/getting-started/platform-api) for deciding between the CLI and direct HTTP calls
- [CLI Authentication](https://www.dwellir.com/docs/cli/authentication) for browser login, profiles, and token resolution
- [Usage & Logs in the CLI](https://www.dwellir.com/docs/cli/usage-and-logs) for terminal-based analytics and cost breakdowns
