> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kiwifs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Analytics and health

> Measure page views and search success, find content gaps, and check knowledge base health.

These endpoints answer two questions: what are people and agents reading and failing to find, and which pages need attention. Analytics and health endpoints need the default SQLite search backend and return `501` when KiwiFS runs with `search.engine = "grep"`.

KiwiFS records a page view on every `GET /api/kiwi/file` for a markdown page, except from known bots. Tag views with `?source=` or the `X-Kiwi-Source` header (default `api`) to break them down by client.

## Health dashboard

Return page counts, health issues, link coverage, recent updates, and engagement in one call. The web UI's analytics panel uses this.

```http theme={null}
GET /api/kiwi/analytics
```

**scope** `string`

Path prefix. Only pages under it are counted.

**stale\_threshold** `integer` (default: 30)

Days used for the stale check. See [Stale pages](#stale-pages).

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics?scope=concepts/'
```

**total\_pages** `integer`

Indexed pages.

**total\_words** `integer`

Sum of word counts.

**health** `object`

Issue groups. Each has `count` and `paths`. Orphans, broken links, and empty pages come from the latest [janitor scan](#janitor-scan).

**properties**

**stale** `object`

Pages past review. See [Stale pages](#stale-pages).

**orphans** `object`

Pages no other page links to.

**broken\_links** `object`

Pages containing a wiki link that doesn't resolve.

**empty** `object`

Pages with no body.

**no\_frontmatter** `object`

Pages without frontmatter. `paths` is always empty.

**coverage** `object`

**properties**

**pages\_with\_links** `integer`

Pages with at least one outgoing link.

**pages\_without\_links** `integer`

Pages with none.

**avg\_links\_per\_page** `number`

Mean outgoing links per page.

**top\_updated** `object[]`

The 10 most recently updated pages, each with `path` and `updated_at`.

**engagement** `object`

**properties**

**total\_views** `integer`

All recorded page views.

**top\_viewed** `object[]`

Most viewed pages. Same shape as [page views](#page-views).

**failed\_searches** `object[]`

Most frequent searches with no results. Same shape as [failed searches](#failed-searches).

```json theme={null}
{
  "total_pages": 142,
  "total_words": 58210,
  "health": {
    "stale": { "count": 2, "paths": ["concepts/legacy-auth.md", "concepts/sso.md"] },
    "orphans": { "count": 1, "paths": ["concepts/caching.md"] },
    "broken_links": { "count": 1, "paths": ["concepts/billing.md"] },
    "empty": { "count": 0, "paths": [] },
    "no_frontmatter": { "count": 12, "paths": [] }
  },
  "coverage": { "pages_with_links": 120, "pages_without_links": 22, "avg_links_per_page": 3.4 },
  "top_updated": [
    { "path": "concepts/auth.md", "updated_at": "2026-10-18T14:30:00Z" }
  ],
  "engagement": {
    "total_views": 3120,
    "top_viewed": [
      { "path": "concepts/auth.md", "count": 412, "first_seen": 1758000000, "last_seen": 1760880000 }
    ],
    "failed_searches": [
      { "query": "oauth refresh token", "search_type": "search", "count": 7, "first_seen": 1759000000, "last_seen": 1760870000 }
    ]
  }
}
```

## Analytics overview

Return headline numbers for a period, each compared with the period before it.

```http theme={null}
GET /api/kiwi/analytics/overview
```

**period** `string` (default: 7d)

Number of days followed by `d`, such as `7d`, `30d`, or `90d`. Invalid values fall back to `7d`.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/overview?period=30d'
```

**period** `string`

Period used.

**total\_views** `integer`

Page views in the period.

**views\_delta\_percent** `number`

Change in views versus the previous period, in percent.

**total\_searches** `integer`

Searches in the period.

**searches\_delta\_percent** `number`

Change in searches, in percent.

**search\_success\_rate** `number`

Share of searches that returned results.

**success\_rate\_delta\_pp** `number`

Change in success rate, in percentage points.

**unique\_pages\_viewed** `integer`

Distinct pages viewed.

**unique\_pages\_delta\_percent** `number`

Change in distinct pages viewed, in percent.

```json theme={null}
{
  "period": "30d",
  "total_views": 3120,
  "views_delta_percent": 12.5,
  "total_searches": 860,
  "searches_delta_percent": -3.1,
  "search_success_rate": 0.91,
  "success_rate_delta_pp": 2.0,
  "unique_pages_viewed": 97,
  "unique_pages_delta_percent": 4.3
}
```

## Page views

Return the most viewed pages, optionally for one page or since a point in time.

```http theme={null}
GET /api/kiwi/analytics/views
```

**top** `integer` (default: 20)

Maximum rows, up to 200.

**path** `string`

Only return views of this page.

**since** `string`

Unix timestamp or RFC 3339 time. Returns `400` if it is neither.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/views?top=5&since=2026-10-01T00:00:00Z'
```

**top** `integer`

Row limit used.

**path** `string`

Path filter, if given.

**since** `integer`

Start time as a Unix timestamp, if given.

**results** `object[]`

**properties**

**path** `string`

Page path.

**count** `integer`

Views.

**first\_seen** `integer`

First view, Unix seconds.

**last\_seen** `integer`

Latest view, Unix seconds.

```json theme={null}
{
  "top": 5,
  "since": 1759276800,
  "results": [
    { "path": "concepts/auth.md", "count": 212, "first_seen": 1759280000, "last_seen": 1760880000 }
  ]
}
```

## Page view time series

Return page views bucketed over time, plus the top 20 pages for the period. Buckets are hourly for periods up to 7 days and daily beyond that.

```http theme={null}
GET /api/kiwi/analytics/views/v2
```

**period** `string` (default: 30d)

Number of days followed by `d`.

**path** `string`

Limit the time series to one page. `top_pages` always covers every page.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/views/v2?period=7d&path=concepts/auth.md'
```

**period** `string`

Period used.

**path** `string`

Path filter, if given.

**time\_series** `object[]`

Buckets, each with `timestamp` (Unix seconds, bucket start) and `count`.

**top\_pages** `object[]`

Up to 20 pages, same shape as [page views](#page-views) results.

```json theme={null}
{
  "period": "7d",
  "path": "concepts/auth.md",
  "time_series": [
    { "timestamp": 1760839200, "count": 4 },
    { "timestamp": 1760842800, "count": 9 }
  ],
  "top_pages": [
    { "path": "concepts/auth.md", "count": 61, "first_seen": 1760300000, "last_seen": 1760880000 }
  ]
}
```

## Search analytics

Return search volume over time, the success rate, and the 20 most frequent failed queries for a period.

```http theme={null}
GET /api/kiwi/analytics/searches
```

**period** `string` (default: 30d)

Number of days followed by `d`.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/searches?period=30d'
```

**period** `string`

Period used.

**search\_success\_rate** `number`

Share of searches that returned results.

**time\_series** `object[]`

Buckets, each with `timestamp` and `count`.

**top\_failed** `object[]`

**properties**

**query** `string`

Query text.

**search\_type** `string`

Which search ran it, such as `search` or `semantic`.

**count** `integer`

Times it was run.

**had\_results** `integer`

Times it returned results.

```json theme={null}
{
  "period": "30d",
  "search_success_rate": 0.91,
  "time_series": [{ "timestamp": 1758240000, "count": 31 }],
  "top_failed": [
    { "query": "oauth refresh token", "search_type": "search", "count": 7, "had_results": 0 }
  ]
}
```

## Failed searches

Return the most frequent searches that returned no results.

```http theme={null}
GET /api/kiwi/analytics/failed-searches
```

**top** `integer` (default: 20)

Maximum rows, up to 200.

**since** `string`

Unix timestamp or RFC 3339 time. Returns `400` if it is neither.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/failed-searches?top=10'
```

**top** `integer`

Row limit used.

**since** `integer`

Start time as a Unix timestamp, if given.

**results** `object[]`

**properties**

**query** `string`

Query text.

**search\_type** `string`

Which search ran it.

**count** `integer`

Times it failed.

**first\_seen** `integer`

First failure, Unix seconds.

**last\_seen** `integer`

Latest failure, Unix seconds.

```json theme={null}
{
  "top": 10,
  "results": [
    { "query": "oauth refresh token", "search_type": "search", "count": 7, "first_seen": 1759000000, "last_seen": 1760870000 }
  ]
}
```

## Trends

Return pages whose views rose or fell most compared with the previous period.

```http theme={null}
GET /api/kiwi/analytics/trends
```

**period** `string` (default: 7d)

Number of days followed by `d`.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/trends?period=7d'
```

**period** `string`

Period used.

**trending** `object[]`

Pages with rising views.

**declining** `object[]`

Pages with falling views. Both arrays share this shape:

**properties**

**path** `string`

Page path.

**current\_views** `integer`

Views in this period.

**previous\_views** `integer`

Views in the previous period.

**delta\_percent** `number`

Change, in percent.

```json theme={null}
{
  "period": "7d",
  "trending": [{ "path": "runbooks/deploy.md", "current_views": 48, "previous_views": 12, "delta_percent": 300 }],
  "declining": [{ "path": "concepts/legacy-auth.md", "current_views": 2, "previous_views": 15, "delta_percent": -86.7 }]
}
```

## Content gaps

Return failed queries that suggest missing pages. Dismissed queries are excluded.

```http theme={null}
GET /api/kiwi/analytics/content-gaps
```

**limit** `integer` (default: 20)

Maximum rows, up to 200.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/content-gaps?limit=10'
```

**results** `object[]`

Same shape as [failed searches](#failed-searches) results.

```json theme={null}
{
  "results": [
    { "query": "oauth refresh token", "search_type": "search", "count": 7, "first_seen": 1759000000, "last_seen": 1760870000 }
  ]
}
```

## Dismiss a content gap

Hide a query from the content gaps list, for example after writing the missing page.

```http theme={null}
POST /api/kiwi/analytics/content-gaps/dismiss
```

**query** `string` *required*

Query text, exactly as listed.

**search\_type** `string` (default: search)

`search_type` from the content gap entry.

```bash theme={null}
curl -X POST 'http://localhost:3333/api/kiwi/analytics/content-gaps/dismiss' \
  -H "Content-Type: application/json" \
  -d '{"query": "oauth refresh token"}'
```

Returns `400` if `query` is missing.

```json theme={null}
{ "dismissed": "oauth refresh token" }
```

## View sources

Return page views in a period grouped by source. The source is the `source` query parameter or `X-Kiwi-Source` header sent with the file read, or `api` when neither is set.

```http theme={null}
GET /api/kiwi/analytics/sources
```

**period** `string` (default: 7d)

Number of days followed by `d`.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/analytics/sources?period=30d'
```

**period** `string`

Period used.

**sources** `object`

Map from source name to view count.

```json theme={null}
{ "period": "30d", "sources": { "ui": 2410, "api": 530, "mcp": 180 } }
```

## Page health check

Return size, link, and freshness metrics and open issues for one page.

```http theme={null}
GET /api/kiwi/health-check
```

**path** `string` *required*

Page path.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/health-check?path=concepts/auth.md'
```

Returns `400` if `path` is missing. A page that isn't indexed returns `200` with the issue `page not found in index`.

**path** `string`

Page path.

**word\_count** `integer`

Words in the page.

**link\_count** `integer`

Outgoing links.

**backlink\_count** `integer`

Incoming links.

**days\_since\_update** `number`

Days since the page last changed.

**quality\_score** `number`

Frontmatter `quality_score`, if set.

**issues** `string[]`

Issues from the latest janitor scan, formatted `kind: message`.

```json theme={null}
{
  "path": "concepts/billing.md",
  "word_count": 342,
  "link_count": 5,
  "backlink_count": 8,
  "days_since_update": 2.4,
  "issues": ["broken-link: link [[payments-v1]] does not resolve"]
}
```

## Stale pages

List pages due for review. A page is stale when its `next-review` date has passed, or, if it has no `next-review`, when its `reviewed` date is older than `days`. Pages with `status: deprecated` or `status: archived` are skipped.

```http theme={null}
GET /api/kiwi/stale
```

**days** `integer` (default: 30)

Age threshold for the `reviewed` fallback.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/stale?days=60'
```

**staleDays** `integer`

Threshold used.

**count** `integer`

Stale pages found.

**results** `object[]`

Pages, each with `path` and `frontmatter`.

```json theme={null}
{
  "staleDays": 60,
  "count": 1,
  "results": [
    { "path": "concepts/legacy-auth.md", "frontmatter": { "title": "Legacy authentication", "next-review": "2026-08-01", "status": "active" } }
  ]
}
```

## Contradictions

List pages that may conflict with a given page. A page is a candidate when it shares a `tags` or `topics` value with the given page and either has a different `status`, or both pages set `source-of-truth: true`.

```http theme={null}
GET /api/kiwi/contradictions
```

**path** `string` *required*

Page path.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/contradictions?path=concepts/auth.md'
```

**path** `string`

Page checked.

**contradictions** `string[]`

Paths of possibly conflicting pages.

```json theme={null}
{ "path": "concepts/auth.md", "contradictions": ["runbooks/login-flow.md"] }
```

## Janitor scan

Return the results of a knowledge base health scan. The server runs scans on a schedule; this endpoint returns the cached result unless you ask for a fresh one or a non-default threshold.

```http theme={null}
GET /api/kiwi/janitor
```

**staleDays** `integer` (default: 90)

Days without changes before a page counts as stale. The default comes from the janitor configuration.

**fresh** `boolean` (default: false)

Run a new scan instead of returning the cached result.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/janitor?fresh=true'
```

Cached responses include an `X-Kiwi-Janitor-LastScan` header with the scan time.

**issues** `object[]`

**properties**

**kind** `string`

`stale`, `orphan`, `duplicate`, `contradiction`, `missing-owner`, `missing-status`, `empty-page`, `broken-link`, `no-review-date`, `decision-found`, `expired-memory`, or `execution-stale`.

**path** `string`

Affected page.

**message** `string`

What's wrong.

**related** `string[]`

Other pages involved, such as the duplicate.

**suggestion** `string`

How to fix it.

**severity** `string`

`error`, `warning`, or `info`.

**scanned** `integer`

Pages scanned.

**healthy** `integer`

Pages with no issues.

**timestamp** `string`

When the scan ran.

```json theme={null}
{
  "issues": [
    {
      "kind": "orphan",
      "path": "concepts/caching.md",
      "message": "no other page links here",
      "suggestion": "link it from a parent topic",
      "severity": "warning"
    }
  ],
  "scanned": 142,
  "healthy": 131,
  "timestamp": "2026-10-19T06:00:00Z"
}
```

## Memory report

Summarize episodic memory: how many episode files exist, how many have been merged into durable pages, and which haven't. See [Episodic memory](https://docs.kiwifs.com/concepts/episodic-memory.md).

```http theme={null}
GET /api/kiwi/memory/report
```

**episodes\_prefix** `string` (default: episodes/)

Folder holding episode files. Defaults to `[memory] episodes_path_prefix` in config.

**limit** `integer`

Maximum entries in `episodic_files` and `unmerged`.

**offset** `integer`

Entries to skip in `episodic_files` and `unmerged`.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/memory/report?limit=50'
```

Returns `400` for a negative or non-numeric `limit` or `offset`. Results are cached for 30 seconds.

**episodic\_count** `integer`

Episode files found.

**total\_episodic** `integer`

Episode files before pagination.

**total\_unmerged** `integer`

Unmerged episodes before pagination.

**merged\_from\_refs** `integer`

`merged-from` references across all pages.

**coverage\_pct** `number`

Percentage of episodes referenced by a `merged-from` entry.

**contradictions** `integer`

Pages flagged as contradicting each other.

**avg\_age\_days** `number`

Mean age of active pages, in days.

**expired\_count** `integer`

Pages whose `expires_at` has passed.

**contested\_count** `integer`

Pages with `memory_status: contested`.

**scope\_counts** `object`

Map from frontmatter `scope` value to page count.

**episodic\_files** `object[]`

Episode files, each with `path` and optional `episode_id` and `memory_kind`.

**unmerged** `object[]`

Episodes not yet merged, same shape.

**warnings** `string[]`

Problems found while scanning. Omitted when empty.

```json theme={null}
{
  "episodic_count": 23,
  "total_episodic": 23,
  "total_unmerged": 8,
  "contradictions": 0,
  "merged_from_refs": 15,
  "coverage_pct": 65.2,
  "avg_age_days": 41.7,
  "expired_count": 1,
  "contested_count": 0,
  "scope_counts": { "team": 18, "personal": 5 },
  "episodic_files": [{ "path": "episodes/ep-001.md", "episode_id": "ep-001" }],
  "unmerged": [{ "path": "episodes/ep-012.md", "episode_id": "ep-012" }]
}
```

## MCP equivalents

`kiwi_analytics` (health dashboard), `kiwi_health_check`, and `kiwi_memory_report`.

## Related

> [card] [Refactor](https://docs.kiwifs.com/api/refactor.md)
>
> Find and fix broken links and orphan pages.

> [card] [Web UI analytics](https://docs.kiwifs.com/guides/web-ui.md#analytics)
>
> The analytics panel built on these endpoints.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.