BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/neon-ui/use-consumption-history

useConsumptionHistory

neon-ui/use-consumption-history
FreeHook

Fetches consumption history through your own proxy route and shapes it into buckets and totals.

Install it

npx shadcn@latest add https://ui.neon.com/r/use-consumption-history.json

Source

src/hooks/use-consumption-history.tsui.neon.com/r/use-consumption-history.json
1"use client";
2
3import { useCallback, useEffect, useRef, useState } from "react";
4
5import type {
6 ConsumptionBucket,
7 ConsumptionGranularity,
8 ConsumptionMetricName,
9 ConsumptionPeriod,
10 ConsumptionTotals,
11} from "@/lib/consumption";
12import {
13 CONSUMPTION_METRICS,
14 flattenConsumption,
15 sumBuckets,
16} from "@/lib/consumption";
17
18/**
19 * Neon refreshes consumption roughly every 15 minutes and the endpoints
20 * share a ~50 req/min bucket, so anything faster than this just burns
21 * quota on numbers that haven't moved.
22 */
23export const MIN_POLL_INTERVAL_MS = 900_000;
24
25export interface UseConsumptionHistoryOptions {
26 /**
27 * Your own route handler that proxies the Neon consumption API. The key
28 * is server-only, so the browser must never call console.neon.tech
29 * directly. Defaults to "/api/consumption".
30 */
31 endpoint?: string;
32 /** RFC 3339 start of the window. */
33 from: string;
34 /** RFC 3339 end of the window. */
35 to: string;
36 granularity: ConsumptionGranularity;
37 /** Defaults to every metric the v2 project endpoint returns. */
38 metrics?: readonly ConsumptionMetricName[];
39 /** Narrow to specific projects; omit for the whole org. */
40 projectIds?: readonly string[];
41 /** Re-fetch on an interval. Clamped to 15 minutes. */
42 pollIntervalMs?: number;
43 /** Set false to hold the request until you're ready. */
44 enabled?: boolean;
45}
46
47export interface UseConsumptionHistoryResult {
48 /** One entry per timeframe, oldest first, raw API units. */
49 buckets: ConsumptionBucket[];
50 /** Every metric summed across the window, raw API units. */
51 totals: ConsumptionTotals;
52 /** The untouched response, for per-project or per-branch splitting. */
53 periods: ConsumptionPeriod[];
54 isLoading: boolean;
55 error: string | null;
56 /** Fetched-at timestamp; pair it with a metering-lag notice. */
57 updatedAt: Date | null;
58 refresh: () => void;
59}
60
61interface ConsumptionResponse {
62 projects?: { project_id: string; periods: ConsumptionPeriod[] }[];
63 branches?: { branch_id: string; periods: ConsumptionPeriod[] }[];
64}
65
66const buildQuery = (options: UseConsumptionHistoryOptions) => {
67 const params = new URLSearchParams({
68 from: options.from,
69 granularity: options.granularity,
70 metrics: (options.metrics ?? CONSUMPTION_METRICS).join(","),
71 to: options.to,
72 });
73
74 if (options.projectIds?.length) {
75 params.set("project_ids", options.projectIds.join(","));
76 }
77
78 return params.toString();
79};
80
81// … truncated

What it pulls in

Other registry items

  • https://ui.neon.com/r/consumption.json

Files it writes

  • src/hooks/use-consumption-history.ts

Facts

Registry
neon-ui
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-12
Last confirmed
today

Go to the source

ui.neon.com neondatabase/ui on GitHub Raw registry item This item as JSON

More from neon-ui

All 77 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useGatewayModelsuse-gateway-modelsneon-uiHooksFreeno deps
useRegionPinguse-region-pingneon-uiHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex