Quick Start
Get up and running with OilPriceAPI in under 5 minutes.
Overview
This guide will help you:
- Get your API key
- Make your first API request
- Understand the response format
- Explore next steps
Step 1: Get Your API Key
Sign Up
- Visit oilpriceapi.com/signup
- Create your account (free tier available)
- Verify your email address
Generate API Key
- Log into your dashboard
- Navigate to API Keys section
- Click Create New Key
- Give it a descriptive name (e.g., "Production App")
- Copy your key immediately - it won't be shown again!
**Tip**: Create separate keys for development and production environments
Step 2: Make Your First Request
Let's fetch the latest oil prices:
Step 3: Understanding the Response
Here's what you'll receive when requesting multiple commodities:
{
"status": "success",
"data": {
"WTI_USD": {
"price": 74.52,
"formatted": "$74.52",
"currency": "USD",
"code": "WTI_USD",
"created_at": "2025-12-29T15:30:00.000Z",
"type": "spot_price",
"source": "oilprice.business_insider"
},
"BRENT_CRUDE_USD": {
"price": 78.30,
"formatted": "$78.30",
"currency": "USD",
"code": "BRENT_CRUDE_USD",
"created_at": "2025-12-29T15:30:00.000Z",
"type": "spot_price",
"source": "oilprice.business_insider"
}
}
}
Key Fields Explained
| Field | Description | Example |
|---|---|---|
price | Current spot price | 74.52 |
formatted | Price with currency symbol | $74.52 |
currency | Price currency code | USD |
code | Commodity identifier | WTI_USD |
created_at | Price timestamp (ISO 8601) | 2025-12-29T15:30:00.000Z |
type | Price type | spot_price |
source | Data source identifier | oilprice.business_insider |
Step 4: Common Use Cases
Get Specific Commodities
# Only get WTI and Natural Gas prices
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,NATURAL_GAS_USD" \
-H "Authorization: Token YOUR_API_KEY"
Get Multiple Commodity Prices
# Get WTI and Brent prices together
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD" \
-H "Authorization: Token YOUR_API_KEY"
Get Historical Data
# Get past 24 hours of WTI data
curl "https://api.oilpriceapi.com/v1/prices/past_day?by_code=WTI_USD" \
-H "Authorization: Token YOUR_API_KEY"
Step 5: Best Practices
1. Store API Keys Securely
Never hardcode API keys:
// ❌ Bad
const apiKey = 'opa_live_abc123';
// ✅ Good
const apiKey = process.env.OILPRICE_API_KEY;
2. Handle Errors Gracefully
try {
const response = await fetch('https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD', {
headers: { 'Authorization': `Token ${apiKey}` }
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Failed to fetch prices:', error);
// Implement fallback logic
}
3. Implement Caching
API updates every 5 minutes, so cache responses:
import time
from functools import lru_cache
@lru_cache(maxsize=1)
def get_cached_prices(cache_key):
response = requests.get(
'https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD',
headers={'Authorization': f'Token {API_KEY}'}
)
return response.json()
# Generate new cache key every 5 minutes
cache_key = int(time.time() // 300)
prices = get_cached_prices(cache_key)
Step 6: Direct API Integration
The API is simple to integrate directly into your application without any additional libraries:
Quick Examples
Price Alert System
async function checkPriceThreshold() {
const response = await fetch('https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD', {
headers: { 'Authorization': `Token ${process.env.OILPRICE_API_KEY}` }
});
const data = await response.json();
const wtiPrice = data.data.WTI_USD.price;
if (wtiPrice > 80) {
sendAlert(`WTI above $80: Currently $${wtiPrice}`);
}
}
// Check every 5 minutes
setInterval(checkPriceThreshold, 5 * 60 * 1000);
Simple Dashboard
<!DOCTYPE html>
<html>
<head>
<title>Oil Prices</title>
</head>
<body>
<h1>Live Oil Prices</h1>
<div id="prices">Loading...</div>
<script>
async function updatePrices() {
// Note: In production, proxy through your backend
const response = await fetch('/api/prices');
const data = await response.json();
document.getElementById('prices').innerHTML = `
<p>WTI: $${data.data.WTI_USD.price}</p>
<p>Brent: $${data.data.BRENT_CRUDE_USD.price}</p>
<p>Last Updated: ${new Date(data.data.WTI_USD.timestamp).toLocaleString()}</p>
`;
}
updatePrices();
setInterval(updatePrices, 60000); // Update every minute
</script>
</body>
</html>
What's Next?
Now that you've made your first request, explore:
- API Reference - All available endpoints
- Authentication Guide - Security best practices
- Making Requests - Request patterns and examples
- Handling Responses - Response parsing and error handling
- Premium Features - Advanced endpoints and features
Need Help?
- Email: [email protected]
- Chat: Available in dashboard
- FAQ - Common questions answered
- Status Page - API health