# Telemetry read API

Read-only keys grant access to one or more explicitly approved Updog projects.
They cannot ingest telemetry or access projects outside their grants.

## Browser login and project access

With CLI 0.7.0 or newer:

1. Run `updog login`.
2. Open the displayed Updog authorization page and sign in if needed.
3. Enter the displayed code and select one or more projects (up to 100).
4. Approve access. The CLI stores one read-only key granting exactly those projects.

No project-selection flag is needed at login. Plain commands automatically query
the projects granted to the current credential:

```sh
updog logs search --query timeout --since 1h
updog errors search --status unresolved --since 7d
updog --all-projects hosts list
updog metrics show zone.tick.work.max --hostname zone-1 --since 6h
```

`--all-projects` queries all saved credential profiles, or the projects granted to
`UPDOG_API_KEY` when supplied. Repeated `--project NAME` selectors still query
existing saved profiles; a profile may grant several projects. `--project` and
`--all-projects` cannot be combined. `--project` cannot use environment authentication.

Up to four requests run concurrently. Filters, sorting, limits, offsets, and
windows apply per project. Multi-project JSON contains `data` entries with
`project` (slug), `project_id`, `url`, and the original API envelope under
`response`; failed entries contain `error`. Top-level `meta` counts `projects`,
`succeeded`, and `failed`. Partial failures preserve successful results and exit
nonzero. Single-project credential output is unchanged.

## MCP server for coding agents

Agents that speak the Model Context Protocol can use Updog without the CLI.
The server is `https://wuzupdog.com/mcp` (Streamable HTTP, JSON-RPC over
POST, no sessions) and authenticates with the same read-only keys as the REST
API, sent as `Authorization: Bearer updog_...` or `X-API-Key`. Create a
read-only key on the project's **API Keys** page, or create one key that grants
several projects at `https://wuzupdog.com/agent-keys/new`, which also shows
copyable Claude Code, Codex, and JSON configuration with the key filled in. One MCP server entry
then covers every granted project: `list_projects` shows them and each tool
takes a `project` argument. Revoking the key from any granted project's API
Keys section revokes MCP access immediately. New read features ship as MCP
tools on deploy, so agents never need a client upgrade.

Tools: `list_projects`, `search_logs`, `list_hosts`, `search_errors`,
`get_error`, `list_metric_names`, and `get_metric_series`. Each mirrors the
matching REST endpoint below, takes the same parameters as named arguments,
returns the same `data`/`meta` envelope as `structuredContent`, and enforces the
same scopes and per-key rate limits. A credential that grants several projects
takes a `project` argument (slug or id); `list_projects` shows the choices.

Claude Code (user scope, so the key stays out of the repository):

```sh
claude mcp add --transport http updog https://wuzupdog.com/mcp \
  --header "Authorization: Bearer ${UPDOG_API_KEY}"
```

Or in a committed `.mcp.json`, which expands environment variables at load time:

```json
{
  "mcpServers": {
    "updog": {
      "type": "http",
      "url": "https://wuzupdog.com/mcp",
      "headers": { "Authorization": "Bearer ${UPDOG_API_KEY}" }
    }
  }
}
```

Codex CLI, in `~/.codex/config.toml`, reading the key from the environment:

```toml
[mcp_servers.updog]
url = "https://wuzupdog.com/mcp"
env_http_headers = { "Authorization" = "UPDOG_MCP_AUTHORIZATION" }
```

with `UPDOG_MCP_AUTHORIZATION="Bearer updog_..."` exported in the shell.
Cursor, Gemini CLI, and VS Code accept the same URL plus a static
`Authorization` header in their MCP server settings. Clients that only support
OAuth-based connectors, such as claude.ai custom connectors, are not supported
by this endpoint yet.

Protocol notes: the server implements `initialize`, `ping`, `tools/list`, and
`tools/call`, accepts protocol versions `2025-06-18`, `2025-03-26`, and
`2024-11-05`, answers notifications with `202`, and returns `405` for `GET`
and `DELETE` because it opens no server-initiated streams. A missing or invalid
credential returns `401` with a `WWW-Authenticate: Bearer` challenge. Tool
problems such as validation errors, missing scopes, rate limits, and telemetry
outages come back as tool results with `isError: true` and a structured
`error` object, so the model can read and recover from them.

## Discover and select projects over HTTP

```http
GET /api/v1/projects
X-API-Key: updog_...
```

Requires `logs:read`, which every CLI-issued credential includes. Returns
`data: [{id, name, slug}, ...]` and `meta: {total}` for that key's grants only.
Discovery is rate-limited under the key's shared `logs:read` bucket.

For a multi-project key, select a granted project on each telemetry request:

```http
GET /api/v1/logs?since=1h
X-API-Key: updog_...
X-Updog-Project-ID: 123
```

Omitting the selector for a multi-project telemetry query returns structured
`400 project_selection_required`. Selecting any ungranted or invalid ID returns
`403 project_not_allowed`. A single-project key may omit the header; specifying
another project never expands access. Ingestion keys remain single-project.

Existing keys and older CLIs keep working. Older CLI login requests retain the
single-project browser selector. New CLIs request multi-selection automatically;
the token response includes a `projects` array alongside the compatible primary
`project` field. Deploy the server first, then CLI 0.7.0. Log in again to issue
one credential for multiple projects; existing tokens are not silently expanded.

## Authentication

Send a read-only key in the request header:

```http
X-API-Key: updog_...
```

Create a single-project key from the project's **API Keys** section, or use browser CLI login to select multiple projects. The secret is shown once, so store it in a secret manager. For noninteractive tools, provide it through `UPDOG_API_KEY` rather than a command-line argument.

Every project member can authorize CLI login or create a manual read-only key for projects they belong to. Ingestion key creation and key listing/revocation remain restricted to owners and admins. A shared key appears to owners and admins in every selected project's **API Keys** section. An owner or admin of any selected project can revoke it; revocation removes all of the key's access. The lowest-ID selected project anchors the credential; deleting that project deletes the whole key, while deleting an additional project removes that grant.

Invalid or revoked credentials return `401`. A key without the required read scope returns `403`. Rate-limited requests return `429` with `Retry-After`.

Every successful response contains `data` and `meta`, uses UTC ISO-8601 timestamps, and includes `Cache-Control: no-store`.

## Search logs

```http
GET /api/v1/logs?q=timeout&level=error&since=1h&limit=50
```

Supported parameters are `q`, `level`, `hostname`, `trace_id`, `since`, `until`, `sort_by`, `sort_dir`, `limit`, and `offset`. The default window is one hour and the maximum window is 14 days; logs are retained for 7 days, so longer windows return at most 7 days of data.

## Inspect hosts

```http
GET /api/v1/hosts
GET /api/v1/hosts?hostname=zone-1
```

Host snapshots contain machine identity, role, environment, agent version, last-seen time, CPU, load, memory, swap, file descriptors, filesystem capacity, disk activity, network interfaces, and the current top processes by CPU and memory. The optional `hostname` parameter selects one exact machine.

## Query metrics

```http
GET /api/v1/metrics/names
GET /api/v1/metrics?name=zone.tick.work.max&since=1h&hostname=zone-1&zone=emerald
```

Requires `metrics:read`. CLI 0.9.0 requests it at login, and the server
deployment grants it to existing CLI and read-only keys.

`GET /api/v1/metrics/names` returns the metric names reported to the project
during the last 7 days as `data: ["host.cpu.utilization", "zone.tick.work.max", ...]`
and `meta: {total}`.

`GET /api/v1/metrics` returns one metric as time buckets. `name` is required.
Optional filters are `hostname`, `service`, `environment`, and, for zone-server
metrics tagged by the Unity client, `zone` and `zone_server_id`; each selects
one exact value. `since` defaults to one hour and the maximum window is 14 days;
metrics are retained for 7 days, so longer windows return at most 7 days of data. Each `data` entry contains `bucket`, `avg`,
`max`, `min`, and `sample_count`; `meta` contains `name`, `bucket_seconds`,
`total`, the applied `filters`, and the normalized `window`. Bucket width grows
with the window, from 5 seconds for windows up to 30 minutes to 3 hours for
windows longer than 7 days, so clients should not assume a fixed interval.

## Search errors

```http
GET /api/v1/errors?q=ArgumentError&status=unresolved&since=7d
```

Error search matches the error class, message, and fingerprint. Supported parameters are `q`, `status`, `since`, `until`, `limit`, and `offset`. Use `since=all` to search all retained error-group summaries.

## Fetch error details

```http
GET /api/v1/errors/123?since=24h&limit=20
```

The response contains the project-scoped error group and its occurrences, including stack traces, breadcrumbs, request data, and context. Occurrences default to the last 24 hours and are retained for at most 90 days.

## Time ranges and pagination

`since` accepts a relative duration such as `30m`, `6h`, or `7d`, an RFC3339 timestamp, or `all`. `until` accepts an RFC3339 timestamp and defaults to the current time.

List endpoints default to 50 results and allow at most 200. Error details default to 20 occurrences and allow at most 100. `offset` defaults to zero and is capped at 10,000. Invalid parameters return `400` with a JSON error response.

Every successful response includes normalized UTC bounds in `meta.window.since` and `meta.window.until`. When paging, reuse the first response's `meta.window.until` as the next request's `until` value so newly arriving telemetry does not shift the result window.

## Rate limits

Responses include `RateLimit-Limit`, `RateLimit-Remaining`, and the Unix timestamp `RateLimit-Reset`. A `429` response also includes `Retry-After`.
