Skip to content

docs(api): document GET /v1/usage usage-metrics endpoint - #103

Merged
sre-helmcode merged 3 commits into
mainfrom
feat/usage-endpoint-docs
Sep 25, 2026
Merged

sre-helmcode merged 3 commits into
mainfrom
feat/usage-endpoint-docs

Conversation

@sre-helmcode

Copy link
Copy Markdown
Contributor

Tracking issue

#102

Summary

  • Documents the new public GET /v1/usage endpoint (shipped in helmcode/nan-cloud-api) in the Scalar-rendered OpenAPI reference and the getting-started guides (EN/ES).
  • Spec-driven: the PUBLIC_SURFACE tripwire test was extended FIRST (observed RED against the unmodified spec), then the spec was written to green; a dedicated /usage contract describe block pins envelope order, param semantics, error wording, and the api_requests cutover caveat field-by-field.

Changes

File Change
src/data/openapi.json /usage path: params (start_date/end_date/cursor/limit with clamping semantics), UsageReport/UsageRow/UsageTotals/UsageModelTotals/UsageAllTime schemas, worked example, 200/400/401/404/409/429/500 responses, Usage tag, rate-limits note
src/lib/openapiSpec.test.ts Tripwire 10→11 routes (/usage); new contract tests (echo window, api_requests caveat on all four schemas, malformed-cursor wording, limit clamping, verbatim error messages, 404/409/500)
src/lib/apiDoc.ts Comment cache updated (endpoint/schema counts)
src/content/docs/getting-started.mdx "Usage metrics" section: curl example, 90-day cap, cursor pagination, echoed effective window
src/content/docs-es/getting-started.mdx Spanish parity section

Test plan

  • npm test — 66 files / 1304 tests green (tripwire RED observed before the spec landed)
  • npm run build — green
  • canonicalParity + docsNav suites confirm the Discord bot text and docs navigation stay fixed points over the new spec
  • UX blocking review APPROVED (2 rounds); QA blocking review APPROVED (3 rounds)

Deploy notes

  • No VERSION file in this repo (Cloudflare Pages deploys on merge to main).
  • Backend contract ground truth: helmcode/nan-cloud-api PR (same tracking issue).

Add the public usage-metrics endpoint to the Scalar-rendered OpenAPI
spec and the quickstart guides:

- openapi.json: /usage path with start_date/end_date/cursor/limit params,
  UsageReport/UsageRow/UsageTotals/UsageModelTotals/UsageAllTime schemas,
  worked example, inline 400 (window > 90 days never clamped, start>end,
  malformed dates, invalid cursor), 401 and 429 (Retry-After, 30 rpm
  budget) responses; 'Usage' tag; rate-limits note in info.description.
- openapiSpec.test.ts: PUBLIC_SURFACE tripwire extended (10 -> 11 routes,
  /usage added) — updated first, observed RED against the unmodified
  spec, GREEN after.
- getting-started.mdx (EN) and getting-started.mdx (ES): 'Usage metrics'
  section with a curl example, window cap and cursor pagination notes.

openapiToText and resolveSpec needed no changes (generic renderer over
paths/tags/params/schemas; canonicalParity test confirms the Discord bot
text stays a fixed point).

Validation: npx vitest run — 66 files / 1294 tests green; npm run build
green.
Review-driven accuracy pass on the /usage documentation:

- UsageReport: document the new top-level start_date/end_date (the
  EFFECTIVE served window after clamping) in schema and examples.
- UsageAllTime: add api_requests.
- cursor param: a MALFORMED cursor returns 400; a well-formed cursor
  only positions the page (previous text wrongly said 'unknown cursor
  returns 400').
- limit param: out-of-range values are server-clamped into 1-500 and
  non-numeric values fall back to 100.
- start_date param: document future-date clamping to today.
- 400 description quotes the new backend messages verbatim (window span
  + remedy, next_cursor hint); 404/409/500 responses documented in the
  file's existing style.
- openapiSpec.test.ts: new contract tests pinning envelope order,
  all_time shape, param semantics, error wording and 404/409/500
  (written first: 8 failed against the previous spec, then green).
- getting-started guides (EN/ES): one parity sentence on the echoed
  effective window.

Validation: vitest 66 files / 1303 tests green; npm run build green.
Request counts only exist from the usage-hook cutover (2026-09-02);
older days report 0. Every api_requests description (row, window
totals, per-model totals, all-time) now states this so tokens-per-
request math in third-party tools does not silently lie for members
active before the cutover.

Also: 404 description now lists the actual identity resolution sources
(API key, Discord link, handle); 400 description covers the malformed
account identity case (param null); new spec test pins the caveat on
all four api_requests fields.
@sre-helmcode sre-helmcode added the documentation Improvements or additions to documentation label Sep 25, 2026
@sre-helmcode
sre-helmcode merged commit 7de23b4 into main Sep 25, 2026
2 checks passed
@sre-helmcode
sre-helmcode deleted the feat/usage-endpoint-docs branch September 25, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants