# API Tokens

API tokens (Bearer tokens) enable you to access Netdata resources programmatically. These tokens authenticate and authorize API requests, allowing you to interact with Netdata services securely from external applications, scripts, or integrations.

:::important

API tokens never expire but should be managed carefully as they grant access to your Netdata resources.

:::

## Token Generation

**Location**

You can access token management through the Netdata UI:

1. Click your profile picture in the bottom-left corner
2. Select "User Settings"
3. Navigate to the API Tokens section

**Available Scopes**

You can limit each token to specific scopes that define its access permissions:

| Scope                  | Description                                                                                                                                        | API Access                         |
|:-----------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------|
| `scope:all`            | Grants the same permissions as the user who created the token. Use case: Terraform provider integration.                                           | Full access to all API endpoints   |
| `scope:agent-ui`       | Used by Agent for accessing the Cloud UI                                                                                                           | Access to UI-related endpoints     |
| `scope:grafana-plugin` | Used for the [Netdata Grafana plugin](https://github.com/netdata/netdata-grafana-datasource-plugin/blob/master/README.md) to access Netdata charts | Access to chart and data endpoints |
| `scope:mcp`            | Used to connect MCP clients (Claude Desktop, Cursor, etc.) to [Netdata Cloud MCP](/docs/netdata-ai/mcp/README.md#netdata-cloud-mcp) for AI-assisted monitoring | Access to MCP server endpoints     |

## API Versions

Netdata provides three API versions that you can access with API tokens:

- **v1**: The original API, focused on single-node operations
- **v2**: Multi-node API with advanced grouping and aggregation capabilities
- **v3**: The latest API version that combines v1 and v2 endpoints and may include additional features

:::tip

**v3 is the recommended version for Netdata Cloud queries.** Netdata Cloud v3 endpoints use POST with a JSON body and provide the most control over scoping, filtering, and aggregation. Local Agent v3 endpoints are available via GET; for example, `/api/v3/data` is query-parameter driven and does not use the Cloud v3 JSON body shape. See the [Common Endpoints section](#common-endpoints) for v3 endpoint details.

:::

## Common Endpoints

With the appropriate token type, you can access endpoints including:
Cloud API tokens authenticate Netdata Cloud endpoints, while direct Local Agent endpoints use per-agent bearer tokens only when Agent bearer protection is enabled (and may not require a token when unprotected).

| Surface                     | Method | Endpoint                                           | Purpose                                                          |
|:----------------------------|:-------|:---------------------------------------------------|:-----------------------------------------------------------------|
| Netdata Cloud               | `POST` | `/api/v3/spaces/{spaceID}/rooms/{roomID}/data`     | Time-series metric data queries                                  |
| Netdata Cloud               | `POST` | `/api/v3/spaces/{spaceID}/rooms/{roomID}/nodes`    | List nodes in a room                                             |
| Netdata Cloud               | `POST` | `/api/v3/spaces/{spaceID}/rooms/{roomID}/contexts` | List available metric contexts                                   |
| Local Agent                 | `GET`  | `/api/v3/data`                                     | v3 data queries (single-node on an Agent, multi-node on a Parent) |
| Local Agent                 | `GET`  | `/api/v3/nodes`                                    | Multi-host node listing on a parent Agent                        |
| Local Agent                 | `GET`  | `/api/v3/contexts`                                 | List available metric contexts on an Agent                       |
| Local Agent                 | `GET`  | `/api/v3/weights`                                  | Metric scoring/correlation                                       |
| Local Agent                 | `GET`  | `/api/v3/q`                                        | Full-text search                                                 |
| Netdata Cloud, Local Agent  | `GET`  | `/api/v2/nodes`                                    | Node information                                                 |
| Netdata Cloud, Local Agent  | `GET`  | `/api/v2/data`                                     | Multi-dimensional data queries                                   |
| Netdata Cloud, Local Agent  | `GET`  | `/api/v2/contexts`                                 | Context metadata                                                 |
| Netdata Cloud, Local Agent  | `GET`  | `/api/v2/weights`                                  | Metric scoring/correlation                                       |
| Netdata Cloud, Local Agent  | `GET`  | `/api/v2/q`                                        | Full-text search                                                 |
| Local Agent                 | `GET`  | `/api/v1/info`                                     | Agent information                                                |
| Local Agent                 | `GET`  | `/api/v1/charts`                                   | Legacy chart information                                         |
| Local Agent                 | `GET`  | `/api/v1/data`                                     | Legacy single-node data queries                                  |

:::caution

The local Agent `/api/v1/charts` endpoint is still available for backward compatibility, but it is deprecated for new integrations. Use `/api/v3/contexts` on local Agents, or `/api/v3/spaces/{spaceID}/rooms/{roomID}/contexts` in Netdata Cloud, to discover current metric contexts and dimensions.

:::

:::note

For Netdata Cloud metric queries, use the room-scoped **v3 POST endpoints** with a JSON body. Local Agents expose their own unscoped v3 endpoints such as `/api/v3/data`, `/api/v3/nodes`, `/api/v3/contexts`, `/api/v3/weights`, and `/api/v3/q`. Legacy metrics v1 endpoints such as `/api/v1/data` and `/api/v1/charts` remain local-Agent only and return **404** when called against `app.netdata.cloud`. v2 endpoints work on both Cloud and local Agents for backward compatibility, but v3 is recommended for Cloud.

:::

## Example Usage

**Get the Netdata Cloud space list**

```console
curl -H 'Accept: application/json' -H "Authorization: Bearer <token>" https://app.netdata.cloud/api/v2/spaces
```

**Get node information**

```console
curl -H 'Accept: application/json' -H "Authorization: Bearer <token>" https://app.netdata.cloud/api/v2/nodes
```

**Query metric data**

```console
curl -H 'Accept: application/json' -H "Authorization: Bearer <token>" https://app.netdata.cloud/api/v2/data?contexts=system.cpu&after=-600
```

:::tip

The examples above use v2 endpoints. For metric data queries, the v3 equivalent (`/api/v3/data`) is also available on local Agents and is used with query parameters. On Netdata Cloud, use the room-scoped v3 POST endpoint and JSON body — see the Advanced Metric Queries example below.

:::

**Advanced Metric Queries with Aggregation**

For more advanced queries with aggregation, use the POST endpoint with a JSON body. This allows you to query metrics with time aggregation (like average values) and control grouping and filtering.

```console
TOKEN="YOUR_API_TOKEN"
SPACE="YOUR_SPACE_ID"
ROOM="YOUR_ROOM_ID"

read -r -d '' PAYLOAD <<'EOF'
{
  "scope": {"contexts": ["system.cpu"]},
  "selectors": {"nodes": ["*"], "contexts": ["*"], "instances": ["*"], "dimensions": ["*"], "labels": ["*"], "alerts": ["*"]},
  "window": {"after": -600, "before": 0, "points": 5},
  "aggregations": {
    "metrics": [{"group_by": ["selected"], "aggregation": "sum"}],
    "time": {"time_group": "average"}
  },
  "format": "json2",
  "options": ["jsonwrap", "minify", "unaligned"],
  "timeout": 30000
}
EOF

curl -s -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v3/spaces/$SPACE/rooms/$ROOM/data" \
  -d "$PAYLOAD"
```

**Time Aggregation Options**

The `time_group` parameter in `aggregations.time` controls how data points within each time interval are combined:

| Option             | Description                                                                        | Use Case                                 |
|:-------------------|:-----------------------------------------------------------------------------------|:-----------------------------------------|
| `average`          | Mean value (default)                                                               | Average resource consumption over time    |
| `min`              | Minimum value                                                                      | Find lowest values in each interval       |
| `max`              | Maximum value                                                                      | Find spikes or peaks                      |
| `sum`              | Sum of values                                                                      | Total volume transferred (counters)       |
| `median`           | Median value                                                                       | Robust central tendency                   |
| `stddev`           | Standard deviation                                                                 | Measure of variability                    |
| `ses`              | Single exponential smoothing                                                       | Trend-aware smoothing                     |
| `des`              | Double exponential smoothing                                                       | Trend + seasonality smoothing             |
| `incremental-sum`  | Difference between last and first value                                            | Change over interval                      |
| `percentile`       | Generic percentile (set value in `time_group_options`)                             | e.g., 95th percentile latency             |
| `countif`          | Count values matching condition (set condition in `time_group_options`)            | e.g., count samples above threshold       |
| `trimmed-mean`     | Mean after trimming outliers (set trim % in `time_group_options`)                  | Robust average excluding extremes         |
| `trimmed-median`   | Median after trimming outliers (set trim % in `time_group_options`)                | Robust median excluding extremes          |
| `extremes`         | Min and max values                                                                 | Show value range per interval             |

:::important

When using `time_group` values other than `min`, `max`, `average`, or `sum`, you MUST specify `"tier": 0` in the `window` object to ensure a non-aggregated storage tier is used. Without it, the query may use a pre-aggregated tier (per-minute or per-hour) where advanced functions like `median`, `stddev`, `ses`, `des`, `percentile`, `countif`, `trimmed-mean`, `trimmed-median`, and `extremes` cannot work correctly.

:::

**Get context information**

```console
curl -H 'Accept: application/json' -H "Authorization: Bearer <token>" https://app.netdata.cloud/api/v2/contexts
```
