Get Started with OilPriceAPI
Source-Timestamped WTI & Brent Data via REST API
Fetch one WTI record with its source timestamp. The publishedoilpriceapi Python package is available alongside the REST API.
7-day free trial: 10,000 API calls; no credit card
Run a Timestamped OilPriceAPI Request
# python -m pip install requests
import math
import os
import requests
key = os.environ.get("OILPRICEAPI_KEY")
if not key:
raise SystemExit("Set OILPRICEAPI_KEY in your environment before running.")
response = requests.get(
"https://api.oilpriceapi.com/v1/prices/latest",
params={"by_code": "WTI_USD"},
headers={"Authorization": "Token " + key},
timeout=15,
)
if response.status_code == 401:
raise SystemExit("API key expired or revoked; create a new key in your account.")
if response.status_code == 429:
raise SystemExit("Rate limited; wait for your quota window and retry.")
response.raise_for_status()
payload = response.json()
record = payload.get("data") if isinstance(payload, dict) else None
if not isinstance(record, dict) or isinstance(record.get("price"), bool) or not isinstance(record.get("price"), (int, float)) or not math.isfinite(record["price"]):
raise SystemExit("No valid price returned; do not substitute zero.")
timestamp = record.get("as_of") or record.get("source_timestamp") or record.get("created_at")
if not isinstance(timestamp, str) or not timestamp:
raise SystemExit("Source timestamp missing; do not use this value.")
print({
"code": record.get("code"),
"price": record["price"],
"currency": record.get("currency"),
"source_timestamp": timestamp,
})// Node.js 18+; set OILPRICEAPI_KEY in your environment.
const key = process.env.OILPRICEAPI_KEY;
if (!key) throw new Error("OILPRICEAPI_KEY is required");
const url = "https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD";
const response = await fetch(url, {
headers: { Authorization: "Token " + key },
signal: AbortSignal.timeout(15000),
});
if (response.status === 401) throw new Error("API key expired or revoked");
if (response.status === 429) throw new Error("Rate limited; retry after your quota window");
if (!response.ok) throw new Error("Price request failed: HTTP " + response.status);
const record = (await response.json()).data;
if (!record || typeof record.price !== "number" || !Number.isFinite(record.price)) {
throw new Error("No valid price returned; do not substitute zero");
}
const timestamp = record.as_of || record.source_timestamp || record.created_at;
if (typeof timestamp !== "string" || !timestamp) {
throw new Error("Source timestamp missing; do not use this value");
}
console.log({
code: record.code,
price: record.price,
currency: record.currency,
source_timestamp: timestamp,
});<?php
$key = getenv('OILPRICEAPI_KEY');
if (!$key) { throw new RuntimeException('OILPRICEAPI_KEY is required'); }
$url = 'https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD';
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ['Authorization: Token ' . $key],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($body === false) { throw new RuntimeException(curl_error($ch)); }
curl_close($ch);
if ($status === 401) { throw new RuntimeException('API key expired or revoked'); }
if ($status === 429) { throw new RuntimeException('Rate limited; retry after your quota window'); }
if ($status !== 200) { throw new RuntimeException('Price request failed: HTTP ' . $status); }
$record = json_decode($body, true, 512, JSON_THROW_ON_ERROR)['data'] ?? null;
if (!is_array($record) || !is_numeric($record['price'] ?? null)) {
throw new RuntimeException('No valid price returned; do not substitute zero');
}
$timestamp = $record['as_of'] ?? $record['source_timestamp'] ?? $record['created_at'] ?? null;
if (!is_string($timestamp) || !$timestamp) {
throw new RuntimeException('Source timestamp missing; do not use this value');
}
print_r([
'code' => $record['code'] ?? null,
'price' => $record['price'],
'currency' => $record['currency'] ?? null,
'source_timestamp' => $timestamp,
]);require 'json'
require 'net/http'
require 'uri'
key = ENV.fetch('OILPRICEAPI_KEY')
uri = URI('https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD')
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Token ' + key
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, open_timeout: 15, read_timeout: 15) do |http|
http.request(request)
end
raise 'API key expired or revoked' if response.code == '401'
raise 'Rate limited; retry after your quota window' if response.code == '429'
raise 'Price request failed: HTTP ' + response.code unless response.is_a?(Net::HTTPSuccess)
record = JSON.parse(response.body).fetch('data')
raise 'No valid price returned; do not substitute zero' unless record['price'].is_a?(Numeric) && record['price'].finite?
timestamp = record['as_of'] || record['source_timestamp'] || record['created_at']
raise 'Source timestamp missing; do not use this value' unless timestamp.is_a?(String) && !timestamp.empty?
puts({
code: record['code'], price: record['price'], currency: record['currency'],
source_timestamp: timestamp
})Why 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
Contact Bloomberg for pricing
- ❌ 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 $24/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 Full API (except licensed datasets: aviation fuel pilot) includes a 7-day trial with 10,000 requests and no credit card. After the trial, the free plan includes 50 requests per day. 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 Full API (except licensed datasets: aviation fuel pilot) includes 10,000 requests over 7 days. Afterward, the free plan includes 50 requests per day. 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.







