Start Using Our Oil Price API in 2 Minutes
import requests
# Get your free API key at oilpriceapi.com
API_KEY = "your_api_key"
url = "https://api.oilpriceapi.com/v1/prices/latest"
headers = {"Authorization": f"Token {API_KEY}"}
response = requests.get(url, headers=headers)
data = response.json()
print(f"WTI: ${data['wti']}/barrel")
print(f"Brent: ${data['brent']}/barrel")
# Response:
# WTI: $63.53/barrel
# Brent: $67.91/barrelconst axios = require('axios');
async function getLatestOilPrices() {
try {
const response = await axios.get('https://api.oilpriceapi.com/v1/prices/latest', {
headers: {
'Authorization': 'Token YOUR_API_KEY',
'Content-Type': 'application/json'
}
});
console.log('WTI Price:', response.data.data.price);
console.log('Last Updated:', response.data.data.updated_at);
return response.data;
} catch (error) {
console.error('Error fetching oil prices:', error.message);
throw error;
}
}
// Get historical data for the past month
async function getHistoricalPrices() {
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
.toISOString()
.split('T')[0];
const response = await axios.get('https://api.oilpriceapi.com/v1/prices', {
params: {
by_code: 'WTI_USD',
start_date: thirtyDaysAgo
},
headers: {
'Authorization': 'Token YOUR_API_KEY'
}
});
return response.data;
}<?php
function getLatestOilPrices() {
$apiKey = 'YOUR_API_KEY';
$url = 'https://api.oilpriceapi.com/v1/prices/latest';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Token ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("API request failed with status: " . $httpCode);
}
$data = json_decode($response, true);
echo "WTI Price: $" . $data['data']['price'] . "\n";
echo "Last Updated: " . $data['data']['updated_at'] . "\n";
return $data;
}
// Get historical data with date range
function getHistoricalPrices($startDate, $endDate) {
$apiKey = 'YOUR_API_KEY';
$url = 'https://api.oilpriceapi.com/v1/prices?' . http_build_query([
'by_code' => 'WTI_USD',
'start_date' => $startDate,
'end_date' => $endDate
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Token ' . $apiKey
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
?>require 'net/http'
require 'json'
require 'uri'
class OilPriceAPI
def initialize(api_key)
@api_key = api_key
@base_url = 'https://api.oilpriceapi.com/v1'
end
def get_latest_prices
uri = URI("#{@base_url}/prices/latest")
request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Token #{@api_key}"
request['Content-Type'] = 'application/json'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
if response.code == '200'
data = JSON.parse(response.body)
puts "WTI Price: $#{data['data']['price']}"
puts "Last Updated: #{data['data']['updated_at']}"
data
else
raise "API request failed: #{response.code} #{response.message}"
end
end
def get_historical_prices(start_date, end_date = nil)
params = {
by_code: 'WTI_USD',
start_date: start_date
}
params[:end_date] = end_date if end_date
uri = URI("#{@base_url}/prices")
uri.query = URI.encode_www_form(params)
request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Token #{@api_key}"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
JSON.parse(response.body)
end
end
# Usage
api = OilPriceAPI.new('YOUR_API_KEY')
api.get_latest_pricesWhy Choose Our Oil Price API?
Source-Timestamped Data
Latest available values include source timestamps; refresh cadence varies by source, market hours, dataset, and plan.
Simple Integration
Clean REST API with SDKs for Python, JavaScript, Ruby, and PHP. Comprehensive documentation with examples.
Account-Aware Access
Dataset access and limits vary by plan, source, and account entitlement. Enterprise contracts can address support, capacity, and delivery requirements.
Historical Data
Access historical oil prices with account-appropriate date ranges and aggregations. Access depends on the commodity, dataset, and current paid plans.
Broad Energy Catalog
A broad catalog spanning crude oil, natural gas, refined products, futures, marine fuels, carbon markets, metals, forex, and selected energy-intelligence datasets.
Developer Support
Active developer community. Email support on all plans. Dedicated support for Enterprise customers.
Oil Price API vs Bloomberg vs Reuters
Bloomberg Terminal
$24,000/year
- ❌ Expensive annual contracts
- ❌ Complex desktop software
- ❌ Requires extensive training
- ❌ Limited API access
Reuters Eikon
$3,600+/year
- ❌ High minimum pricing
- ❌ Per-user licensing
- ❌ Limited historical data
- ❌ Sales negotiations required
Oil Price API ⭐
From $49/month
- ✅ Pay as you grow
- ✅ Simple REST API
- ✅ 5-minute integration
- ✅ Start free, upgrade anytime
Related API Resources
Frequently Asked Questions
How much does the Oil Price API cost?
The Core commodity API includes a 7-day trial with 10,000 requests and no credit card. After the trial, the free plan includes 200 requests per month. See the pricing page for current paid plans.
What oil prices does the API provide?
A broad catalog spanning crude oil, natural gas, refined products, futures, marine fuels, carbon markets, metals, forex, and selected energy-intelligence datasets. Dataset access and limits vary by plan, source, and account entitlement.
How accurate is your oil price data?
Values include source timestamps so you can evaluate freshness for your workflow. Latest available values include source timestamps; refresh cadence varies by source, market hours, dataset, and plan.
Can I get historical oil price data?
Historical endpoints are available, but the date range, aggregation options, and access vary by commodity, dataset, plan, and account entitlement.
What's the API response time?
Response time varies with endpoint, payload, network location, and load. OilPriceAPI is intended for dashboards, alerts, reporting, and research workflows; evaluate it against your own latency requirements.
Do you have rate limits?
Yes. During the trial, the Core commodity API includes 10,000 requests over 7 days. Afterward, the free plan includes 200 requests per month. Paid and enterprise limits depend on the current plan or contract.
Can I use this for commercial projects?
OilPriceAPI sells API access, normalization, monitoring, and delivery. Standard plans do not grant ownership of underlying source data or unrestricted raw-data redistribution rights. Review the Data Usage Policy.
What authentication method do you use?
Use API key authentication with the Authorization: Token YOUR_API_KEY header. Keys can be regenerated from the account dashboard.







