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/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 |
Similar APIs
Didn't find what you were looking for? Suggest an improvement
/v1/oilprice GET
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 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, Professional, or annual subscriptions onlyComma-separated list of benchmarks for a batch request (e.g.
wti,brent,natural_gas).
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
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_24hThe day's high price.
low_24hThe 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.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/oilprice?type=wtiHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
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.
/v1/oilpricehistorical GETPremium 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
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).
Historical Price Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/oilpricehistorical?type=wti&period=1hHeaders
X-Api-KeyLog in or sign up to get your API KeyHistorical Price Sample Response
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,exchange,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.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,metric_ton) 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.