WTI Crude Price API: WTI_CRUDE as JSON
You need a clean, dependable way to pull today’s West Texas Intermediate crude price into your app, job, or report. By the end of this guide you’ll request WTI under the WTI_CRUDE symbol from Energy API, parse the JSON, handle edge cases like missing fields and errors, and ship a small script that reads the price you need.
What you get from the WTI endpoint
Energy API exposes the latest WTI crude price via a single HTTP GET:
- Endpoint: GET /api/v1/latest
- Query parameters: symbols=WTI_CRUDE and api_key
- Response JSON: includes a rates object keyed by symbol; read rates.WTI_CRUDE
The same response can also include metadata such as currencies.WTI_CRUDE, which helps you understand the currency context of the price. Keep your parser flexible: read only the fields you need (primarily rates.WTI_CRUDE), and treat anything else as optional.
Get started in four steps
- Register — 7-day trial / 50 calls.
- Copy your api_key from your dashboard.
- Call GET /api/v1/latest with symbols=WTI_CRUDE and your api_key.
- Read rates.WTI_CRUDE from the JSON response.
Request: latest WTI
Use curl to fetch the latest WTI crude price. Replace YOUR_API_KEY with your actual key:
curl -s "https://energy-api.com/api/v1/latest?symbols=WTI_CRUDE&api_key=YOUR_API_KEY"
curl "https://energy-api.com/api/v1/latest?symbols=WTI_CRUDE&api_key=YOUR_API_KEY"
Official sample JSON and how to interpret it
The official published sample below is for a related mix that does not include WTI_CRUDE. It is provided so you can see the shape of the JSON. Your live WTI call (with symbols=WTI_CRUDE) follows the same structure—read rates.WTI_CRUDE in your response.
{
"success": true,
"date": "2026-06-11",
"base": "MIXED",
"rates": {
"BRENT_CRUDE": 74.82,
"TTF_GAS": 38.15,
"EUA_CO2": 67.40,
"OMIE_ES_DA": 82.30
}
}
How to read the JSON you’ll receive for WTI:
- success: Boolean that indicates whether the request worked. Always check this before using the data. If success is false, do not use the numbers—log the error and retry or alert.
- rates: Object keyed by symbol. For your WTI call, read rates.WTI_CRUDE.
- currencies: May include symbol-level currency context. For WTI, check currencies.WTI_CRUDE if present to understand the pricing currency context provided by the API.
- Other top-level fields: Treat them as informational. Use them if they exist in your specific response; do not hardcode assumptions beyond the symbol keys you request.
Because the official sample shown here is not WTI, you won’t see rates.WTI_CRUDE in it. That’s expected. When you call the endpoint with symbols=WTI_CRUDE, your JSON will include that key inside rates.
Code: read WTI_CRUDE in Python
This example requests the same endpoint and extracts the two fields you’ll typically need. It also handles errors and missing keys safely.
import os
import sys
import json
import time
import urllib.parse
import urllib.request
API_BASE = "https://energy-api.com/api/v1/latest"
API_KEY = os.environ.get("ENERGY_API_KEY", "YOUR_API_KEY")
SYMBOL = "WTI_CRUDE"
def fetch_latest(symbol):
params = {
"symbols": symbol,
"api_key": API_KEY,
}
url = f"{API_BASE}?{urllib.parse.urlencode(params)}"
req = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(req, timeout=10) as resp:
if resp.status != 200:
raise RuntimeError(f"HTTP {resp.status}")
payload = json.loads(resp.read().decode("utf-8"))
return payload
def read_wti(payload):
# Validate success flag if present
if isinstance(payload, dict) and ("success" in payload) and (payload["success"] is not True):
# Prefer not to proceed with data if API marked it as unsuccessful
msg = payload.get("error") or "API returned success=false"
raise RuntimeError(msg)
rates = payload.get("rates") or {}
wti = rates.get(SYMBOL)
if wti is None:
raise KeyError(f"rates.{SYMBOL} is missing in response")
# Optional currency context if present
currencies = payload.get("currencies") or {}
wti_ccy = currencies.get(SYMBOL)
return {
"wti_price": wti,
"currency_context": wti_ccy,
}
if __name__ == "__main__":
try:
latest = fetch_latest(SYMBOL)
result = read_wti(latest)
print(json.dumps(result, indent=2))
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
Practical integration details that save time
Authentication and endpoint shape
- Authentication: pass api_key as a query parameter. Store your key in an environment variable; never commit it to source control.
- Endpoint: GET /api/v1/latest with symbols=WTI_CRUDE. You can request multiple symbols, but this post focuses on WTI only.
Symbols and what to read
- Symbol for West Texas Intermediate: WTI_CRUDE
- Primary field to read: rates.WTI_CRUDE
- Optional context: currencies.WTI_CRUDE (if present) for the pricing currency context returned by the API.
Base currency considerations
- If you only need WTI_CRUDE, you can omit any base parameter.
- If you also plan to pull TTF_GAS or EUA_CO2 alongside WTI, do not pass base=USD; base may be MIXED across commodities. Keep your code flexible and read the currency context that accompanies each symbol.
Units, dates, and timezones
- Units and currency: Use currencies.WTI_CRUDE if present to determine currency context for the symbol. Do not assume a fixed currency across all symbols.
- Timestamps and dates: Use the date/time fields provided in your response if present. If your downstream system requires timezone awareness, store timestamps as returned and convert at the boundary of your application.
- Non-trading days and updates: Energy prices may not update on weekends or holidays. Cache responses on your side and detect when a value is unchanged across requests.
Caching and refresh strategy
- Short-term cache: Cache the latest response for a brief interval appropriate to your use case. This reduces redundant calls and smooths over temporary network issues.
- Staleness checks: If the API includes a timestamp or date, compare it to your last-seen value to decide whether to refresh dependent computations.
- Retry/backoff: On transient HTTP errors or success=false responses, implement exponential backoff to avoid hot loops.
Error handling and missing values
- Always check success. If success is false, log the payload, do not trust any numbers, and retry later or alert.
- Guard against missing keys. Access rates and currencies via get() and handle None — e.g., if rates.WTI_CRUDE is missing, surface a clear error in logs.
- Type safety. Treat values as numbers only after verifying their type; emit metrics if parsing fails.
Going to production
- Observability: Log the request URL (without the api_key), HTTP status, and whether the response had success=true.
- Secrets: Keep api_key in environment variables or a secret manager.
- No alternate hosts: There is no MCP host—use the documented endpoint.
Copy-paste: WTI with curl
The request below is the same call your production job will make. Swap in your key and run:
curl -s "https://energy-api.com/api/v1/latest?symbols=WTI_CRUDE&api_key=YOUR_API_KEY"
Parse rates.WTI_CRUDE from the JSON. If success is present and false, handle it as an error and do not proceed with the numbers.
Pricing and trial
Starter is $19.99/mo (5,000 calls, 5 symbols) and includes a 7-day trial with 50 calls. That is enough to wire up your integration, test error handling, and verify that your cache and monitors behave as expected before you scale up.
Where to go next
- Documentation — endpoint reference and field descriptions.
- Register — get your 7-day trial / 50 calls and an api_key.
FAQ
How do I get only WTI without extra symbols?
Call GET /api/v1/latest with symbols=WTI_CRUDE and your api_key. Read rates.WTI_CRUDE from the response.
Why does the official sample not show WTI_CRUDE?
The published sample illustrates the JSON structure but does not include WTI. When you request symbols=WTI_CRUDE, your response will include rates.WTI_CRUDE with the value you need.
Should I force a base currency?
If you also need TTF_GAS or EUA_CO2, do not pass base=USD because base may be MIXED. Read the currency context per symbol if present.
What do I do when success is false?
Treat it as an error: do not use the numbers. Back off and retry, and surface an alert if the condition persists.
How should I cache?
Cache the latest response briefly to cut redundant calls and handle temporary outages. Use any returned date/time fields to detect staleness and only recompute downstream values when the data changes.
Ready to wire this into your codebase? Start your 7-day trial, get an api_key, and ship your first call to rates.WTI_CRUDE in minutes: Register.
Ready to get started?
Get your API key and start querying energy commodity prices in minutes.
Get API Key