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": {
"WTI_USD": {
"name": "West Texas Intermediate Crude Oil",
"price": 78.45,
"currency": "USD",
"unit": "barrel",
"timestamp": "2025-07-18T10:30:00Z",
"change_24h": 0.82,
"change_percent_24h": 1.05,
"day_high": 79.20,
"day_low": 77.50,
"market_status": "open"
}
},
"meta": {
"request_id": "req_abc123def456",
"response_time_ms": 42,
"generated_at": "2025-07-18T10:30:15Z"
}
}
Response Fields
Field | Type | Description |
---|---|---|
name | string | Full commodity name |
price | number | Current price |
currency | string | Price currency (default: USD) |
unit | string | Price unit (barrel, mmbtu, etc.) |
timestamp | string | ISO 8601 timestamp of price update |
change_24h | number | Absolute price change in last 24 hours |
change_percent_24h | number | Percentage change in last 24 hours |
day_high | number | Highest price today |
day_low | number | Lowest price today |
market_status | string | Market status (open/closed) |
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 getLatestPrices() {
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();
return data.data.WTI_USD.price;
}
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_code
parameter when possible - Use field selection: Request only needed fields with
fields
parameter - 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