Oil Price API
The Oil Price API provides real-time and historical crude oil prices through a simple REST API. Query the WTI (West Texas Intermediate) and Brent crude benchmarks, plus natural gas, heating oil, and RBOB gasoline, and get clean JSON back from a single GET request.
Available endpoints:
- /v1/oilprice - Access the current oil price for a benchmark
- /v1/oilspot - Access the official daily spot price for a benchmark
- /v1/oilpricehistorical - Access historical oil prices (OHLCV)
For gold, metals, grains, and 25+ other commodities, see our Commodity Price API.
The API covers these oil & energy benchmarks (sample daily-close prices):
| Benchmark | type | Sample price |
|---|---|---|
| WTI Crude | wti | $67.82/bbl |
| Brent Crude | brent | $71.45/bbl |
| Natural Gas | natural_gas | $4.12/MMBtu |
| Heating Oil | diesel | $2.31/gal |
| RBOB Gasoline | gasoline | $2.14/gal |
From 8,188 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 365ms | 396ms | 416ms | 691ms | 1291ms |
Didn't find what you were looking for? Suggest an improvement
https://api.api-ninjas.com/v1/oilprice
Returns the current price for an oil or energy benchmark. Free accounts receive the daily closing price for WTI and Brent; premium members get real-time prices for all benchmarks. For official physical spot prices, see /v1/oilspot; for historical prices, see /v1/oilpricehistorical.
Parameters
typeoptionalThe benchmark to return. One of
wti(default),brent,natural_gas,gasoline, ordiesel(No. 2 heating oil / ULSD). Each maps to a benchmark you can also explore on its own page: WTI Crude, Brent Crude, Natural Gas, Heating Oil, RBOB Gasoline.currencyoptional Premium onlyISO 4217 currency code to convert the price into (e.g.
EUR,GBP). Defaults to USD.unitoptional Premium onlyTarget unit to convert the price into. Must match the benchmark's dimension: crude oil, gasoline, and diesel (priced by volume) accept
barrel,gallon,liter, orcubic_meter; natural gas (priced by energy) acceptsMMBtu,MWh,GJ, ortherm.typesoptional Business tier and above, or any annual planComma-separated list of benchmarks for a batch request (e.g.
wti,brent,natural_gas).
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
The /v1/oilprice endpoint returns a JSON object with the following fields, or an error if the request is unsuccessful.
typeThe requested benchmark (e.g.
wti).nameThe display name of the benchmark (e.g. Crude Oil).
priceThe current price (daily close on the free tier, real-time on premium).
unitThe quote unit (e.g.
barrel,gallon,MMBtu).currency_unitThe price currency (
USDby default).previous_closeThe previous session's closing price.
change_24hThe change versus the previous close.
change_24h_percentThe percent change versus the previous close.
high_24hPremium onlyThe day's high price.
low_24hPremium onlyThe day's low price.
high_52wPremium onlyThe 52-week high price.
low_52wPremium onlyThe 52-week low price.
updatedThe Unix timestamp (in seconds) of the price.
futures_contractThe futures contract
priceis quoted for (e.g.CLX26, November 2026 WTI).futures_contract_monthThe contract's delivery month (
YYYY-MM).
Live Demo
Code Examples
curl -X GET "https://api.api-ninjas.com/v1/oilprice?type=wti" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
Premium only
https://api.api-ninjas.com/v1/oilspot
Returns the daily spot price at a benchmark's physical delivery hub, for example WTI at Cushing, Oklahoma, or natural gas at Henry Hub. For the live futures price, see /v1/oilprice.
Update frequency: daily prices, published with a delay, so they trail the futures price by several days. date is the trading day each price is for.
Parameters
typeoptionalThe benchmark:
wti(default),brent,natural_gas,gasoline, ordiesel.currencyoptionalISO 4217 currency code to convert the price into (e.g.
EUR). Defaults to USD.unitoptionalTarget unit, in the benchmark's dimension:
barrel,gallon,liter, orcubic_meterfor oil, gasoline, and diesel;MMBtu,MWh,GJ, orthermfor natural gas.typesoptional Business tier and above, or any annual planComma-separated list of benchmarks for a batch request (e.g.
wti,brent,natural_gas).
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
The /v1/oilspot endpoint returns a JSON object with the following fields, or an error if the request is unsuccessful.
typeThe requested benchmark (e.g.
wti).nameThe display name of the benchmark.
priceThe spot price: the price for immediate delivery.
spot_typeHow the spot price is produced:
assessed(the daily spot price at the benchmark's delivery hub).dateThe trading day the price is for (
YYYY-MM-DD). Daily spot prices are published with a delay, so it trails by several days.benchmarkThe physical spot benchmark: WTI Cushing, Oklahoma; Brent Europe; Henry Hub; New York Harbor conventional regular gasoline; or New York Harbor ultra-low sulfur diesel.
previous_closeThe spot price on the previous trading day.
change_24hThe change versus the previous trading day.
change_24h_percentThe percent change versus the previous trading day.
updatedThe Unix timestamp (in seconds) of the spot price.
unitThe quote unit (changes when the
unitparameter is used).currency_unitThe price currency (
USDby default).
Live Demo
Code Examples
curl -X GET "https://api.api-ninjas.com/v1/oilspot?type=wti" \
-H "X-Api-Key: YOUR_API_KEY"Premium only
https://api.api-ninjas.com/v1/oilpricehistorical
Returns historical oil price data in OHLCV (Open, High, Low, Close, Volume) format. The data is returned in descending order (most recent first).
Parameters
typeoptionalThe benchmark:
wti(default),brent,natural_gas,gasoline, ordiesel.periodoptionalTime interval between data points. Valid values are:
1m,5m,15m,30m,1h,4h,1d. Default is1h.startoptionalStart timestamp in Unix format. If not provided, defaults to a recent window for the chosen period.
endoptionalEnd timestamp in Unix format. If not provided, defaults to current time.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
The /v1/oilpricehistorical endpoint returns a JSON array of OHLCV objects with the following fields, or an error if the request is unsuccessful.
openThe opening price for this time period.
lowThe lowest price during this time period.
highThe highest price during this time period.
closeThe closing price for this time period.
volumeThe trading volume during this time period.
timeThe timestamp for this data point in Unix format (in seconds).
provisionalWhether daily-bar volume is still being finalized.
Live Demo
Code Examples
curl -X GET "https://api.api-ninjas.com/v1/oilpricehistorical?type=wti&period=1h" \
-H "X-Api-Key: YOUR_API_KEY"Frequently Asked Questions
Can I use the Oil Price API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Oil Price API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Oil Price API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Oil Price API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What oil and energy prices does the Oil Price API provide?
The Oil Price API returns real-time and historical prices for the major energy benchmarks: WTI crude oil (type=wti), Brent crude oil (type=brent), natural gas, heating oil (type=diesel), and RBOB gasoline. Use/v1/oilpricefor the latest price and/v1/oilpricehistoricalfor OHLCV history. For metals, grains, and 25+ other commodities, see the Commodity Price API.Is there a free oil price API?
Yes. Create a free account to get an instant API key and start pulling oil prices at no cost. The free tier returns the daily closing price for WTI (type=wti) and Brent (type=brent); premium plans unlock real-time prices, all five benchmarks, currency and unit conversion, and the historical endpoint. One key works across every API Ninjas endpoint.How do I get real-time WTI and Brent crude oil prices in Python or JSON?
Send a GET request to/v1/oilprice?type=wtifor WTI ortype=brentfor Brent, passing your key in theX-Api-Keyheader. The response is a JSON object withtype,name,price(USD per barrel),unit,currency_unit, and anupdatedUnix timestamp. Copy-paste examples in Python, cURL, and Node.js are shown above. Real-time prices require a premium plan; free keys return the daily close.Does the Oil Price API return spot prices as well as futures prices?
Yes, from a separate endpoint./v1/oilpricereturns the live futures price, with the contract it is quoted for infutures_contract./v1/oilspotreturns the daily spot price at the benchmark's physical delivery hub (for example WTI at Cushing, Oklahoma, or Henry Hub for natural gas), named inbenchmark. Daily spot prices are published with a delay, sodatetells you which trading day the spot price is for; it typically trails the futures price by several days./v1/oilspotis available on premium plans.How do I get historical oil prices?
Call/v1/oilpricehistoricalwith atypeplus the optionalperiod(1m,5m,15m,30m,1h,4h,1d; default1h) andstart/endUnix timestamps. It returns OHLCV data (open, high, low, close, volume, time) most-recent-first. The historical endpoint is premium only.Can I get oil prices in other currencies or units, such as per gallon or in EUR?
Yes. On/v1/oilprice, add thecurrencyparameter (an ISO 4217 code likeEURorGBP) and/or theunitparameter (barrel,gallon,liter,cubic_meter) to convert the price — for example, crude oil per gallon in euros. Conversion is available on premium plans.What is the difference between WTI and Brent crude oil prices?
WTI (West Texas Intermediate) is the primary US crude benchmark, traded on CME/NYMEX; Brent is the global benchmark used to price much of the world's internationally-traded crude, traded on ICE. The two usually differ by a few dollars per barrel (the Brent-WTI spread). Query either from the same API withtype=wtiortype=brent, or see the dedicated WTI and Brent pages.
Explore API integration use cases for recommended APIs and workflow examples.