Henry Hub on Energy API: First Request with curl and JSON

Henry Hub on Energy API: First Request with curl and JSON

You need a fast, correct way to fetch the latest Henry Hub natural-gas price from the Energy API and read it in your app. By the end of this guide, you will make a working request with curl, reproduce it in Python, and parse the exact fields that matter (rate, date, unit, and currency) for Henry Hub.

What you’re building

This is a first-request walkthrough for the Energy API symbol “Henry Hub” (code: HENRY_HUB). You will hit a single endpoint that returns the most recent price and metadata, learn what each field means, and integrate a minimal client that you can expand later. We will keep it practical—just enough to ship: one endpoint, one symbol, one call, one parser.

If you want to dive deeper later, keep the official Documentation handy in another tab.

Prerequisites and key facts

  • Symbol name: Henry Hub
  • Symbol code: HENRY_HUB
  • Unit: USD/MMBtu
  • HTTP method: GET
  • Endpoint: https://energy-api.com/api/v1/latest
  • Auth: api_key query parameter (use YOUR_API_KEY in examples below)
  • Query parameter for symbol selection: symbols=HENRY_HUB
  • Fields to read: rates.HENRY_HUB, dates.HENRY_HUB, currencies.HENRY_HUB, plus top-level base
  • Base may be “MIXED” when asking for multiple symbols in different currencies. For a single symbol like HENRY_HUB, base will typically match the symbol currency (USD).
  • Plan notes: Starter $19.99/mo, trial 7 days / 50 calls.

Important constraint if you later request multiple energy symbols together: do not pass an explicit base=USD when you also need symbols in other native currencies (for example, TTF_GAS or EUA_CO2). Mixed baskets can produce base=MIXED; read currencies.[symbol] instead of forcing a base.

The minimal request

Your first call asks for the latest reading for HENRY_HUB with your API key included as a query parameter. This is the smallest working request you can make.

Code: curl

curl -G "https://energy-api.com/api/v1/latest" --data-urlencode "symbols=HENRY_HUB" --data-urlencode "api_key=YOUR_API_KEY"

If the call succeeds, you will receive a JSON payload that includes the latest rate, the date associated with that rate, the base currency context, and per-symbol currencies. You can copy and paste the above curl command to verify your credentials and connectivity before writing any application code.

A real JSON response and how to read it

Below is a real response for Henry Hub. Use the same field names and structure in your code; do not assume undocumented fields.

Code: JSON response

{"success":true,"date":"2026-09-22","base":"USD","rates":{"HENRY_HUB":2.9},"dates":{"HENRY_HUB":"2026-09-22"},"currencies":{"HENRY_HUB":"USD"},"base_filter_note":null}

How to read this payload:

  • success: true indicates the call was processed successfully.
  • date: "2026-09-22" is a top-level convenience date aligned with the latest set; for per-symbol precision, use dates.HENRY_HUB.
  • base: "USD" is the overall base of the response. When you request a single USD-quoted symbol like HENRY_HUB, this will commonly be USD. When requesting multiple cross-currency energy symbols in a single call, base may be "MIXED".
  • rates.HENRY_HUB: 2.9 is the latest price of Henry Hub.
  • currencies.HENRY_HUB: "USD" indicates the currency for the Henry Hub rate.
  • dates.HENRY_HUB: "2026-09-22" is the specific date for the Henry Hub observation.

Units matter: Henry Hub is quoted in USD per MMBtu (USD/MMBtu). If you graph or store this value, always keep the unit along with the price to avoid confusion with other gas benchmarks.

Reproduce the same call in Python

Below is a compact Python example that calls the same endpoint, checks for success, and extracts the numeric rate, the date, and the currency for Henry Hub. Run it as-is after replacing YOUR_API_KEY with your key.

Code: Python

import requests

API_URL = "https://energy-api.com/api/v1/latest"
params = {
"symbols": "HENRY_HUB",
"api_key": "YOUR_API_KEY"
}

resp = requests.get(API_URL, params=params, timeout=20)
resp.raise_for_status() # raises if HTTP status is 4xx/5xx

data = resp.json()
if not data.get("success", False):
raise RuntimeError("Energy API call did not succeed")

# Extract fields you actually need
rate = data["rates"]["HENRY_HUB"]
obs_date = data["dates"]["HENRY_HUB"]
currency = data["currencies"]["HENRY_HUB"]
base = data.get("base")

print(f"Henry Hub price: {rate} {currency}/MMBtu on {obs_date} (base={base})")

Notes on parsing and safety:

  • Always check success before reading fields.
  • Use dates.HENRY_HUB for the per-symbol date; it is authoritative for the symbol-specific observation.
  • Use currencies.HENRY_HUB for the per-symbol currency; do not assume the top-level base applies when you later request multiple symbols.
  • Timeouts: set a client timeout so your app doesn’t hang if the network stalls.

What to log, store, and display

For operational clarity, persist or log the following alongside the numeric rate:

  • Symbol code: HENRY_HUB
  • Rate: from rates.HENRY_HUB
  • Currency: from currencies.HENRY_HUB (USD)
  • Unit: USD/MMBtu (fixed for Henry Hub)
  • Observation date: from dates.HENRY_HUB (ISO date string)
  • Top-level base: from base (may be "USD" or "MIXED" depending on your request scope)

Keeping both currency and unit next to the price prevents accidental mixing with other gas hubs or carbon benchmarks. If you later add TTF_GAS or EUA_CO2 to the same call, treat each symbol’s currency from currencies.[symbol] as the canonical reference. If you find base equals "MIXED", that is expected behavior for cross-currency baskets.

Caching and refresh strategy

Energy benchmarks like Henry Hub are typically published on a daily schedule. In many applications, you do not need per-minute refreshes for this endpoint. A common pattern is:

  • Cache the response for the trading day, and refresh after the expected update time or once per day.
  • If your UI requires “last updated” text, read dates.HENRY_HUB to anchor the display to the correct observation date.
  • If you miss a day or request outside publish windows, your next call should still return the latest available reading; handle this gracefully in the UI.

If you perform intraday polling, back off to a reasonable interval and cache responses to conserve your trial or plan call budget (trial: 7 days / 50 calls; Starter: $19.99/mo). When in doubt, check the Documentation for updates on symbol cadence.

Error handling and diagnostics

Expect and handle these conditions:

  • HTTP errors (4xx/5xx): log status code and response body. In Python, resp.raise_for_status() will surface these immediately.
  • success=false in JSON: do not parse rates if the call is not successful. Surface the message to logs if provided.
  • Missing fields: guard access with dictionary lookups and clear error messages so you can diagnose mis-specified symbols or query errors quickly.

For interactive debugging, keep a copy of the actual response payload in logs (with sensitive data like the api_key redacted from URLs) so you can reconcile field names quickly against your code.

Working with multiple symbols later

While this article focuses on Henry Hub alone, your next step might be to fetch a small basket of energy benchmarks in one call. You can pass a comma-separated list to symbols, and the response will include entries in rates, dates, and currencies for each requested symbol. Keep these points in mind:

  • Do not pass base=USD when you also need symbols in other native currencies (for example, TTF_GAS or EUA_CO2). Let the API return the native currencies and check currencies.[symbol].
  • If you observe base="MIXED", this is by design. Your logic should read currencies.[symbol] and not assume a shared base.
  • If your application needs a common-currency view, perform your own conversion downstream using appropriate FX data and the per-symbol currencies from the response.

Testing checklist before shipping

  • Authentication: verify that adding api_key=YOUR_API_KEY returns success=true.
  • Field mapping: confirm your code reads rates.HENRY_HUB, dates.HENRY_HUB, currencies.HENRY_HUB, and base.
  • Units and display: ensure you show USD/MMBtu next to the number.
  • Error paths: simulate a bad key and an invalid symbol to confirm your errors are clean and actionable.
  • Caching: implement a minimal cache (even in-memory) to avoid redundant calls within the same session or display refresh.

Operational notes that save time

  • Symbol stability: use the code HENRY_HUB in your integration; do not rely on display names to build queries.
  • Observation date: always bind data downstream to dates.HENRY_HUB so you do not mix days when recomputing charts or aggregates.
  • Numeric precision: store the rate as decimal/float in your database layer with enough precision to hold at least two decimals for USD. Display rounding can differ from storage.
  • Time zones: the date field is an ISO calendar date string. If you need to timestamp UI refreshes, also log your fetch time separately in UTC to differentiate observation date from retrieval time.
  • Replays: since the endpoint returns the latest value, keep a copy of previous responses if you want historical comparisons; this guide focuses on the latest endpoint only.

Troubleshooting common pitfalls

  • “Parsing error: KeyError: HENRY_HUB” — Verify you requested symbols=HENRY_HUB and check success=true before parsing.
  • “Unexpected currency in chart” — Use currencies.HENRY_HUB for the price label; do not infer from base when you start combining symbols.
  • “Stale data in UI” — Check dates.HENRY_HUB. If your view filters by current date but the observation date is prior, either adjust the UI copy to “as of” or schedule refresh after the daily update time.
  • “Excessive API calls on page load” — Add a per-session or per-minute cache layer. Many UIs do not need to call more than once per load.

Security and deployment tips

  • Do not hardcode your production key in client-side code. Route requests through your backend and keep the key server-side.
  • If you must demo from the browser, use a restricted or ephemeral key and rate-limit by IP on your server proxy.
  • Log only the last 4 characters of the key for diagnostics; avoid storing raw keys in application logs.

End-to-end example flow

Here’s a simple, reliable flow you can adopt immediately:

  1. On service start, perform a single warm-up call with symbols=HENRY_HUB and your api_key to validate connectivity.
  2. On each request needing Henry Hub, retrieve the cached object if it’s fresh for the day; otherwise, refetch.
  3. Expose a normalized DTO to your UI with fields: symbol (HENRY_HUB), value (2.9 example), currency (USD), unit (USD/MMBtu), date (2026-09-22 example), base (USD or MIXED), and fetched_at (UTC timestamp from your server).
  4. In rendering, show “2.9 USD/MMBtu (as of 2026-09-22)”. This keeps your users aware of the reference date.

FAQ

Q1: What endpoint should I call for Henry Hub’s latest price?
A1: Use GET https://energy-api.com/api/v1/latest with symbols=HENRY_HUB and your api_key as a query parameter.

Q2: Which fields should I read to display the price and date?
A2: Read rates.HENRY_HUB for the numeric value, dates.HENRY_HUB for the observation date, and currencies.HENRY_HUB for the currency. You can also inspect the top-level base; it may be “MIXED” if you request multiple cross-currency symbols.

Q3: What unit is Henry Hub quoted in?
A3: USD per MMBtu (USD/MMBtu). Include the unit in charts and summaries to avoid confusion with other gas benchmarks.

Q4: Can I request multiple energy symbols at once?
A4: Yes, by passing a comma-separated list to symbols. Do not force base=USD if you include symbols in different native currencies. Instead, use currencies.[symbol] for each returned series.

Q5: How can I avoid burning trial calls during development?
A5: Cache successful responses for the session or for a suitable interval, and only refetch on demand or after the expected daily update. The trial includes 7 days / 50 calls, so local caching is especially helpful.

Ready to integrate Henry Hub in your stack? Create your key and make your first call in minutes: Register. If you need field-by-field details or want to expand to more energy symbols, keep the Documentation open while you build.

Ready to get started?

Get your API key and start querying energy commodity prices in minutes.

Get API Key

Related posts