Skip to main content

Neon: Generate Project Cost Reports with Node.js

Learn how to solve the lack of per-project cost breakdown in Neon's dashboard by using a custom Node.js script to fetch API data and export CSV reports.

AI-written
Inewgen
29 Oct 2026Source: Dev.to3 min read (0 views)
Share
Neon: Generate Project Cost Reports with Node.js

Stock photo for illustration only, not from the actual event

Font size
  • Neon bills compute in CU-hours, but its dashboard lacks a simple per-project monthly cost breakdown.
  • Developers can use a Node.js script to pull consumption history via API and output a rollup CSV.
  • Compute cost calculation divides compute_unit_seconds by 3600 and multiplies by the rate per CU-hour.
  • Running the report requires NEON_API_KEY and specifying a target month argument like oct-2026.

For developers managing multiple projects under a single organization on Neon (neon.tech), tracking and obtaining a spend report per project is essential for better operations, budgeting, and planning.

The primary challenge is that Neon bills compute resources by CU-hours, yet the native dashboard does not provide a straightforward monthly cost breakdown for each individual project. To bridge this gap, a lightweight Node.js script can be created to pull each project's consumption history and compile it into a CSV rollup file containing one row per project, total CU-seconds, CU-hours, dollar costs, and an organization-wide TOTAL row.

In modern cloud database management, having granular visibility into project-level costs is critical for engineering teams to spot over-provisioned resources and manage budgets effectively. Automating data extraction via APIs eliminates manual spreadsheet work and prevents unexpected billing spikes at the end of the billing cycle.

server room data center office meeting no logo

Stock photo for illustration only, not from the actual event

The core issue with Neon's usage API is that it returns raw metrics per project on a daily basis, including compute-unit seconds, storage bytes, and network transfer. However, developers must stitch together multiple API steps to arrive at an actionable cost figure.

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

The script accepts a month argument (such as oct-2026), fetches the organization's consumption history from the Neon API, and generates three files, with the rollup CSV serving as the primary document utilized each month.

1 CU1 vCPU + 4 GB RAM
3600Seconds per CU-hour

Neon bills compute as CU-hours, where 1 CU equals 1 vCPU combined with 4 GB of RAM. The API reports compute_unit_seconds already pre-multiplied (meaning a 2-CU endpoint running for one wall-clock second registers as 2 compute_unit_seconds). Consequently, the cost math follows these steps:

  • Convert seconds to hours: const hours = compute_unit_seconds / 3600
  • Calculate total cost: const cost = hours * RATE_USD_PER_CU_HOUR

To execute the report, developers run the command node scripts/org-neon-usage-report.mjs oct-2026. The process requires a NEON_API_KEY set in the environment or .env.local file, while NEON_ORG_ID defaults to the user's organization but remains overrideable via environment variables.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article