A typed, self-describing wrapper around the EIA APIv2. One query endpoint, 15 data domains and a built-in MCP server — running locally in minutes.
# annual coal production & price, 2020–2024 curl -X POST localhost:3000/query \ -H 'content-type: application/json' \ -d '{"domain":"coal","route":"aggregate-production", "frequency":"annual","data":["production","price"], "start":"2020","end":"2024"}' # → { "response": { "total": N, "data": [ … ] } }
Discover, inspect, query — without hard-coding a single energy domain.
/domains, /search and facet endpoints expose use cases, tags and example queries at runtime.
A single POST /query fetches coal, electricity, natural gas, STEO, SEDS and more.
/guide ships workflows, decision trees and recipes — fetch once, use as a system prompt.
An RDF-style graph bridges “Coal emits CO₂” to concrete EIA domains. Export as JSON-LD or Turtle.
Caching, request spacing, 429 back-off and normalized errors protect your EIA key.
TypeBox schemas flow into routes and Eden Treaty clients. Zero any.
Interactive docs at /openapi and a JSON spec at /openapi/json, generated from the code.
Set MCP_ENABLED=true for 9 tools and 2 resources at /mcp.
One small server between your code and the EIA. REST and MCP share the same validated core.
The server's types flow straight into your client. No codegen, no hand-written interfaces.
import { treaty } from '@elysiajs/eden' import type { App } from './src' const api = treaty<App>('localhost:3000') const { data, error } = await api.query.post({ domain: 'coal', route: 'aggregate-production', frequency: 'annual', data: ['production'], }) // typed, autocompleted data?.response.data[0] // domain: 'nope' is a compile error // and a 422 at runtime
Bodies are validated at runtime and typed from the same TypeBox schema.
Normalized EIA responses with typed errors — no more guessing at upstream shapes.
Domains, routes, facets and frequencies are discovered from the live EIA metadata.
429s are backed off and retried; everything else surfaces as a typed error.
The OpenAPI spec is generated from the same schemas, so it can't drift from the code.
# start the API, then open the docs bun dev http://localhost:3000/openapi # Swagger UI http://localhost:3000/openapi/json # OpenAPI 3.1
# generate a client in any language
bunx openapi-typescript spec.json -o api.d.ts
bunx @openapitools/openapi-generator-cli \
generate -i spec.json -g python -o ./client
Discover first, then query. Every endpoint is plain HTTP.
# search by topic curl -X POST localhost:3000/search \ -H 'content-type: application/json' \ -d '{"q": "solar"}' # → domains, routes, tags, example queries
# filter by facet curl -X POST localhost:3000/query \ -H 'content-type: application/json' \ -d '{"domain":"electricity","route":"retail-sales", "frequency":"monthly","data":["price"], "facets":{"stateid":["TX"],"sectorid":["RES"]}}'
# list domains / fetch the agent playbook
curl localhost:3000/domains
curl localhost:3000/guide
# run the bundled examples
bun run examples/02-discovery.ts
bun run examples/06-query-post-basic.ts
bun run examples/agent-usage.ts
Set MCP_ENABLED=true and the same surface is exposed at /mcp as 9 tools and 2 resources.
Install, configure, query.
# run it bun install cp .env.example .env # set EIA_API_KEY in .env bun dev # http://localhost:3000
# discover, then query curl localhost:3000/domains curl -X POST localhost:3000/query \ -H 'content-type: application/json' \ -d '{"domain":"coal","route":"aggregate-production", "frequency":"annual","data":["production"]}'
This site is static documentation. The API is self-hosted and needs your own free EIA key (get one here), which must never be published in a browser.