NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

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:

For gold, metals, grains, and 25+ other commodities, see our Commodity Price API.

The API covers these oil & energy benchmarks (sample daily-close prices):

BenchmarktypeSample price
WTI Crudewti$67.82/bbl
Brent Crudebrent$71.45/bbl
Natural Gasnatural_gas$4.12/MMBtu
Heating Oildiesel$2.31/gal
RBOB Gasolinegasoline$2.14/gal
(4.5)

From 8,188 users

2,700+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
365ms396ms416ms691ms1291ms

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

  • type  optional

    The benchmark to return. One of wti (default), brent, natural_gas, gasoline, or diesel (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.

  • currency  optional premium only

    ISO 4217 currency code to convert the price into (e.g. EUR, GBP). Defaults to USD.

  • unit  optional premium only

    Target unit to convert the price into. Must match the benchmark's dimension: crude oil, gasoline, and diesel (priced by volume) accept barrel, gallon, liter, or cubic_meter; natural gas (priced by energy) accepts MMBtu, MWh, GJ, or therm.

  • types  optional Business, Professional, or annual subscriptions only

    Comma-separated list of benchmarks for a batch request (e.g. wti,brent,natural_gas).

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON object with the following fields or an error if the request is unsuccessful.

  • type

    The requested benchmark (e.g. wti).

  • name

    The display name of the benchmark (e.g. Crude Oil).

  • price

    The current price (daily close on the free tier, real-time on premium).

  • unit

    The quote unit (e.g. barrel, gallon, MMBtu).

  • currency_unit

    The price currency (USD by default).

  • previous_close

    The previous session's closing price.

  • change_24h

    The change versus the previous close.

  • change_24h_percent

    The percent change versus the previous close.

  • high_24h

    The day's high price.

  • low_24h

    The day's low price.

  • high_52w premium only

    The 52-week high price.

  • low_52w premium only

    The 52-week low price.

  • updated

    The Unix timestamp (in seconds) of the price.

Sample Request Live Demo!

type

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=wti

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
{
    unit:"barrel",
    currency_unit:"USD",
    name:"Crude Oil",
    price:84.8,
    change_24h_percent:-6.25691,
    change_24h:-5.66,
    low_24h:83.9,
    high_24h:86.12,
    high_52w:119.48,
    low_52w:54.98,
    previous_close:90.46,
    updated:1785128296,
    type:"wti"
}

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

  • type  optional

    The benchmark: wti (default), brent, natural_gas, gasoline, or diesel.

  • period  optional

    Time interval between data points. Valid values are: 1m, 5m, 15m, 30m, 1h, 4h, 1d. Default is 1h.

  • start  optional

    Start timestamp in Unix format. If not provided, defaults to a recent window for the chosen period.

  • end  optional

    End timestamp in Unix format. If not provided, defaults to current time.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON array of OHLCV objects with the following fields or an error if the request is unsuccessful.

  • open

    The opening price for this time period.

  • low

    The lowest price during this time period.

  • high

    The highest price during this time period.

  • close

    The closing price for this time period.

  • volume

    The trading volume during this time period.

  • time

    The timestamp for this data point in Unix format (in seconds).

Historical Price Sample Request Live Demo!

type
period
start
end

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=1h

Headers

X-Api-KeyLog in or sign up to get your API Key

Historical Price Sample Response

JSON
[
    {
      open:67.4,
      low:67.05,
      high:68.11,
      close:67.82,
      volume:154200,
      time:1741046400
    },
    {
      open:67.91,
      low:67.2,
      high:68.05,
      close:67.4,
      volume:168300,
      time:1740960000
    },
    "..."
]

Frequently Asked Questions

  • 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.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • 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.
  • 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.
  • 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/oilprice for the latest price and /v1/oilpricehistorical for OHLCV history. For metals, grains, and 25+ other commodities, see the Commodity 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.
  • Send a GET request to /v1/oilprice?type=wti for WTI or type=brent for Brent, passing your key in the X-Api-Key header. The response is a JSON object with type, name, exchange, price (USD per barrel), unit, currency_unit, and an updated Unix 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.
  • Call /v1/oilpricehistorical with a type plus the optional period (1m, 5m, 15m, 30m, 1h, 4h, 1d; default 1h) and start/end Unix timestamps. It returns OHLCV data (open, high, low, close, volume, time) most-recent-first. The historical endpoint is premium only.
  • Yes. On /v1/oilprice, add the currency parameter (an ISO 4217 code like EUR or GBP) and/or the unit parameter (barrel, gallon, liter, metric_ton) to convert the price — for example, crude oil per gallon in euros. Conversion is available on premium plans.
  • 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 with type=wti or type=brent, or see the dedicated WTI and Brent pages.