Get Latest Prices
Returns the most recent prices for all or specific commodities.
GET/v1/prices/latest
Authentication
See Authentication Guide for API key setup.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
by_code | string | No | Commodity code(s), comma-separated |
fields | string | No | Specific fields to return, comma-separated |
Response
Success (200)
{
"status": "success",
"data": {
"price": 62.56,
"formatted": "$62.56",
"currency": "USD",
"code": "WTI_USD",
"created_at": "2025-09-30T20:27:42.177Z",
"type": "spot_price",
"source": "oilprice.business_insider",
"metadata": {
"source": "oilprice.business_insider",
"source_description": "Business Insider - Most accurate source matching ICE exchange prices (within $0.27)"
}
}
}
Response Fields
Note: The response contains a single price object directly in the
datafield, not nested by commodity code.
| Field | Type | Description |
|---|---|---|
price | number | Current price value (rounded to 2 decimals) |
formatted | string | Price formatted with currency symbol (e.g., "$62.56") |
currency | string | Price currency code (USD, EUR, GBP) |
code | string | Commodity code (e.g., "WTI_USD") |
created_at | string | ISO 8601 timestamp with milliseconds (UTC) |
type | string | Price type: "spot_price", "daily_average", "weekly_average", etc. |
source | string | Data source identifier |
metadata.source | string | Data source identifier (duplicate for backwards compatibility) |
metadata.source_description | string | Human-readable description of data source accuracy |
Errors
| Code | Status | Description |
|---|---|---|
INVALID_COMMODITY | 400 | Invalid commodity code provided |
INVALID_API_KEY | 401 | Missing or invalid API key |
RATE_LIMIT_EXCEEDED | 429 | Rate limit exceeded |
Examples
# Get all latest prices
curl "https://api.oilpriceapi.com/v1/prices/latest" \
-H "Authorization: Token YOUR_API_KEY"
# Get specific commodity
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD" \
-H "Authorization: Token YOUR_API_KEY"
# Get multiple commodities with specific fields
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD&fields=price,timestamp" \
-H "Authorization: Token YOUR_API_KEY"
// JavaScript
async function getLatestPrice() {
const response = await fetch('https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD', {
headers: {
'Authorization': 'Token YOUR_API_KEY'
}
});
const data = await response.json();
// Access the price directly from data object
console.log(`Current price: ${data.data.formatted}`); // "$62.56"
console.log(`Numeric value: ${data.data.price}`); // 62.56
console.log(`Source: ${data.data.metadata.source_description}`);
return data.data.price;
}
# Python
import requests
def get_latest_price(commodity_code='WTI_USD'):
url = 'https://api.oilpriceapi.com/v1/prices/latest'
headers = {'Authorization': 'Token YOUR_API_KEY'}
params = {'by_code': commodity_code}
response = requests.get(url, headers=headers, params=params)
data = response.json()
price = data['data']['price']
formatted = data['data']['formatted']
print(f"Current {commodity_code}: {formatted}")
return price
# Get multiple commodities
def get_multiple_prices(codes=['WTI_USD', 'BRENT_CRUDE_USD', 'NATURAL_GAS_USD']):
url = 'https://api.oilpriceapi.com/v1/prices/latest'
headers = {'Authorization': 'Token YOUR_API_KEY'}
params = {'by_code': ','.join(codes)}
response = requests.get(url, headers=headers, params=params)
return response.json()['data']
# Ruby
require 'net/http'
require 'json'
require 'uri'
def get_latest_price(commodity_code = 'WTI_USD')
uri = URI("https://api.oilpriceapi.com/v1/prices/latest?by_code=#{commodity_code}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Token YOUR_API_KEY'
response = http.request(request)
data = JSON.parse(response.body)
price = data['data']['price']
puts "Current #{commodity_code}: $#{price}"
price
end
Rate Limits
| Plan | Requests/Month | Requests/Minute |
|---|---|---|
| Free | 1,000 | 10 |
| Hobby | 10,000 | 100 |
| Professional | 100,000 | 1,000 |
Rate limit headers are included in responses:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1736784000
Best Practices
- Cache responses: Prices update every 5 minutes
- Request specific commodities: Use
by_codeparameter when possible - Use field selection: Request only needed fields with
fieldsparameter - Handle rate limits: Check
X-RateLimit-*headers and implement backoff
Related Endpoints
- Historical Prices - Past price data
- Commodities List - Available commodity codes
- WebSocket Streaming - Real-time updates