Diesel Price API: Real-Time Fuel Data for Trucking & Fleet Software
Diesel fuel represents 25-40% of trucking operating costs. For fleet management software, fuel card platforms, and logistics applications, accurate diesel pricing is essential for fuel surcharge calculations, route optimization, and budget forecasting. This guide shows how to integrate diesel price data into your applications.
Why Diesel Pricing Data Matters
For Fleet Management Software
| Use Case | Business Impact |
|---|---|
| Fuel surcharge automation | Accurate customer billing |
| Route cost estimation | Profitability by lane |
| Fuel budget forecasting | Cash flow planning |
| Procurement timing | Optimal buying decisions |
| Driver reimbursement | Fair per-diem calculations |
For Logistics Platforms
| Use Case | Business Impact |
|---|---|
| Spot rate calculators | Accurate carrier quotes |
| Lane profitability | Margin analysis by route |
| Contract escalators | Automated rate adjustments |
| Customer invoicing | Transparent fuel costs |
Understanding US Diesel Pricing
DOE Price Regions (PADDs)
The US Energy Information Administration (EIA) publishes weekly retail diesel prices by PADD region:
| PADD | Region | Coverage |
|---|---|---|
| 1A | New England | CT, MA, ME, NH, RI, VT |
| 1B | Central Atlantic | DE, DC, MD, NJ, NY, PA |
| 1C | Lower Atlantic | FL, GA, NC, SC, VA, WV |
| 2 | Midwest | IL, IN, IA, KS, KY, MI, MN, MO, NE, ND, OH, OK, SD, TN, WI |
| 3 | Gulf Coast | AL, AR, LA, MS, NM, TX |
| 4 | Rocky Mountain | CO, ID, MT, UT, WY |
| 5 | West Coast | AK, AZ, CA, HI, NV, OR, WA |
| National | US Average | Weighted average |
California Diesel
California often has the highest diesel prices due to:
- State fuel taxes (~$0.70/gallon vs. ~$0.24 federal)
- CARB reformulated diesel requirements
- Cap-and-trade carbon costs
California data is broken out separately for many fleet applications.
Accessing Diesel Price Data via API
Get National Diesel Price
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=US_DIESEL_NATIONAL_USD" \
-H "Authorization: Token YOUR_API_KEY"
Response:
{
"status": "success",
"data": {
"price": 3.892,
"formatted": "$3.89/gallon",
"currency": "USD",
"code": "US_DIESEL_NATIONAL_USD",
"name": "US Diesel (National Average)",
"unit": "gallon",
"created_at": "2026-01-27T12:00:00.000Z",
"change": 0.032,
"change_percent": 0.83,
"source": "EIA"
}
}
Get Regional Diesel Prices
# All PADD regions
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=US_DIESEL_PADD1A_USD,US_DIESEL_PADD1B_USD,US_DIESEL_PADD1C_USD,US_DIESEL_PADD2_USD,US_DIESEL_PADD3_USD,US_DIESEL_PADD4_USD,US_DIESEL_PADD5_USD" \
-H "Authorization: Token YOUR_API_KEY"
# California specifically
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=US_DIESEL_CALIFORNIA_USD" \
-H "Authorization: Token YOUR_API_KEY"
Get Historical Diesel Prices
Analyze price trends for forecasting:
# Past 30 days national average
curl "https://api.oilpriceapi.com/v1/prices/past_month?by_code=US_DIESEL_NATIONAL_USD&interval=1d" \
-H "Authorization: Token YOUR_API_KEY"
# Past year (requires premium tier)
curl "https://api.oilpriceapi.com/v1/prices/historical?by_code=US_DIESEL_NATIONAL_USD&start_date=2025-01-01&end_date=2026-01-31" \
-H "Authorization: Token YOUR_API_KEY"
Diesel Commodity Codes
Regional Codes
| Code | Description | Update Frequency |
|---|---|---|
US_DIESEL_NATIONAL_USD | National average | Weekly (Monday) |
US_DIESEL_PADD1A_USD | New England | Weekly |
US_DIESEL_PADD1B_USD | Central Atlantic | Weekly |
US_DIESEL_PADD1C_USD | Lower Atlantic | Weekly |
US_DIESEL_PADD2_USD | Midwest | Weekly |
US_DIESEL_PADD3_USD | Gulf Coast | Weekly |
US_DIESEL_PADD4_USD | Rocky Mountain | Weekly |
US_DIESEL_PADD5_USD | West Coast | Weekly |
US_DIESEL_CALIFORNIA_USD | California | Weekly |
Related Fuel Codes
| Code | Description | Use Case |
|---|---|---|
HEATING_OIL_USD | No. 2 Heating Oil | Wholesale diesel proxy |
GASOLINE_USD | RBOB Gasoline | Fleet fuel mix |
NATURAL_GAS_USD | Henry Hub | CNG fleet fuel |
Integration Examples
Python: Fuel Surcharge Calculator
import requests
from datetime import datetime
from typing import Optional
class FuelSurchargeCalculator:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.oilpriceapi.com/v1"
self.headers = {"Authorization": f"Token {api_key}"}
# Standard surcharge formula parameters
self.base_fuel_price = 1.25 # Historical baseline (DOE average)
self.surcharge_per_dollar = 0.01 # 1 cent per dollar above baseline
def get_current_diesel(self, region: str = "NATIONAL") -> float:
"""Get current diesel price for region."""
code = f"US_DIESEL_{region.upper()}_USD"
response = requests.get(
f"{self.base_url}/prices/latest",
params={"by_code": code},
headers=self.headers
)
return response.json()["data"]["price"]
def calculate_surcharge_percent(self, diesel_price: float) -> float:
"""Calculate fuel surcharge percentage."""
if diesel_price <= self.base_fuel_price:
return 0.0
overage = diesel_price - self.base_fuel_price
surcharge = overage * self.surcharge_per_dollar * 100
return round(surcharge, 2)
def get_surcharge_by_region(self):
"""Get fuel surcharges for all PADD regions."""
regions = [
"NATIONAL", "PADD1A", "PADD1B", "PADD1C",
"PADD2", "PADD3", "PADD4", "PADD5", "CALIFORNIA"
]
surcharges = {}
for region in regions:
price = self.get_current_diesel(region)
surcharge = self.calculate_surcharge_percent(price)
surcharges[region] = {
"diesel_price": price,
"surcharge_percent": surcharge
}
return surcharges
def calculate_lane_fuel_cost(
self,
origin_region: str,
dest_region: str,
miles: float,
mpg: float = 6.5
) -> dict:
"""Calculate fuel cost for a lane."""
gallons_needed = miles / mpg
origin_price = self.get_current_diesel(origin_region)
dest_price = self.get_current_diesel(dest_region)
avg_price = (origin_price + dest_price) / 2
return {
"miles": miles,
"mpg": mpg,
"gallons_needed": round(gallons_needed, 1),
"avg_diesel_price": round(avg_price, 3),
"estimated_fuel_cost": round(gallons_needed * avg_price, 2),
"origin_region": origin_region,
"dest_region": dest_region
}
# Usage
calculator = FuelSurchargeCalculator("YOUR_API_KEY")
# Get current fuel surcharges by region
surcharges = calculator.get_surcharge_by_region()
print("Regional Fuel Surcharges:")
for region, data in surcharges.items():
print(f" {region}: ${data['diesel_price']:.3f}/gal → {data['surcharge_percent']}%")
# Calculate fuel cost for a specific lane
lane = calculator.calculate_lane_fuel_cost(
origin_region="PADD3", # Houston
dest_region="PADD1B", # New York
miles=1750,
mpg=6.5
)
print(f"\nHouston → New York ({lane['miles']} mi):")
print(f" Fuel needed: {lane['gallons_needed']} gallons")
print(f" Avg price: ${lane['avg_diesel_price']}/gal")
print(f" Fuel cost: ${lane['estimated_fuel_cost']}")
JavaScript: Fleet Dashboard Widget
class DieselPriceWidget {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = "https://api.oilpriceapi.com/v1";
this.baseFuelPrice = 1.25; // Baseline for surcharge calc
}
async getAllRegionalPrices() {
const codes = [
"US_DIESEL_NATIONAL_USD",
"US_DIESEL_PADD1A_USD",
"US_DIESEL_PADD1B_USD",
"US_DIESEL_PADD1C_USD",
"US_DIESEL_PADD2_USD",
"US_DIESEL_PADD3_USD",
"US_DIESEL_PADD4_USD",
"US_DIESEL_PADD5_USD",
"US_DIESEL_CALIFORNIA_USD",
].join(",");
const response = await fetch(
`${this.baseUrl}/prices/latest?by_code=${codes}`,
{ headers: { Authorization: `Token ${this.apiKey}` } },
);
const data = await response.json();
return data.data.prices || [data.data];
}
async getPriceHistory(region = "NATIONAL", days = 30) {
const code = `US_DIESEL_${region}_USD`;
const endpoint = days <= 7 ? "past_week" : "past_month";
const response = await fetch(
`${this.baseUrl}/prices/${endpoint}?by_code=${code}&interval=1d`,
{ headers: { Authorization: `Token ${this.apiKey}` } },
);
const data = await response.json();
return data.data.prices;
}
calculateSurcharge(dieselPrice) {
if (dieselPrice <= this.baseFuelPrice) return 0;
return ((dieselPrice - this.baseFuelPrice) * 0.01 * 100).toFixed(2);
}
formatRegionName(code) {
const names = {
US_DIESEL_NATIONAL_USD: "National Avg",
US_DIESEL_PADD1A_USD: "New England",
US_DIESEL_PADD1B_USD: "Central Atlantic",
US_DIESEL_PADD1C_USD: "Lower Atlantic",
US_DIESEL_PADD2_USD: "Midwest",
US_DIESEL_PADD3_USD: "Gulf Coast",
US_DIESEL_PADD4_USD: "Rocky Mountain",
US_DIESEL_PADD5_USD: "West Coast",
US_DIESEL_CALIFORNIA_USD: "California",
};
return names[code] || code;
}
async renderDashboard() {
const prices = await this.getAllRegionalPrices();
return prices.map((p) => ({
region: this.formatRegionName(p.code),
price: p.price,
formatted: `$${p.price.toFixed(3)}/gal`,
change: p.change,
changePercent: p.change_percent,
surcharge: this.calculateSurcharge(p.price),
updatedAt: p.created_at,
}));
}
}
// Usage
const widget = new DieselPriceWidget(process.env.OILPRICE_API_KEY);
const dashboard = await widget.renderDashboard();
console.log("Diesel Prices by Region:");
dashboard.forEach((r) => {
console.log(` ${r.region}: ${r.formatted} (Surcharge: ${r.surcharge}%)`);
});
Webhook: Automated Surcharge Updates
Set up webhooks to receive price updates automatically:
curl -X POST "https://api.oilpriceapi.com/v1/webhooks" \
-H "Authorization: Token YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-fleet-software.com/api/diesel-updates",
"commodity_codes": ["US_DIESEL_NATIONAL_USD"],
"trigger": "price_change"
}'
Your endpoint receives:
{
"event": "price_update",
"timestamp": "2026-01-27T12:00:00.000Z",
"data": {
"code": "US_DIESEL_NATIONAL_USD",
"price": 3.892,
"previous_price": 3.86,
"change": 0.032,
"change_percent": 0.83,
"source": "EIA"
}
}
Use Cases
1. Fuel Surcharge Automation
Most freight contracts include fuel surcharge tables linked to DOE diesel prices. Automate the lookup and calculation:
If DOE National Diesel = $3.892/gallon
And Contract Baseline = $1.25/gallon
And Rate = 1% per $0.10 above baseline
Surcharge = ($3.892 - $1.25) / $0.10 × 1% = 26.42%
2. Route Cost Estimation
Calculate fuel costs for lane analysis:
def estimate_route_fuel_cost(origin_padd, dest_padd, miles, mpg=6.5):
"""Estimate fuel cost for a trucking route."""
origin_price = get_diesel_price(origin_padd)
dest_price = get_diesel_price(dest_padd)
# Average of origin and destination regions
avg_price = (origin_price + dest_price) / 2
gallons = miles / mpg
fuel_cost = gallons * avg_price
return {
"miles": miles,
"gallons": round(gallons, 1),
"fuel_cost": round(fuel_cost, 2),
"cost_per_mile": round(fuel_cost / miles, 3)
}
3. Fuel Budget Forecasting
Track diesel trends for budget planning:
- Compare current vs. 30/60/90-day averages
- Calculate budget variance
- Forecast fuel expenses based on historical patterns
4. Driver Reimbursement
Calculate fair fuel reimbursements based on regional prices where drivers actually fill up:
def calculate_driver_reimbursement(fill_region, gallons):
"""Calculate driver reimbursement based on regional diesel price."""
regional_price = get_diesel_price(fill_region)
reimbursement = gallons * regional_price
return round(reimbursement, 2)
5. Carrier Rate Adjustments
Adjust carrier contracts based on fuel price changes:
def adjust_carrier_rate(base_rate, current_diesel, baseline_diesel=2.50):
"""Adjust carrier rate based on fuel price change."""
fuel_change = (current_diesel - baseline_diesel) / baseline_diesel
adjustment_factor = 0.30 # Fuel is ~30% of carrier costs
rate_adjustment = base_rate * fuel_change * adjustment_factor
adjusted_rate = base_rate + rate_adjustment
return {
"base_rate": base_rate,
"current_diesel": current_diesel,
"rate_adjustment": round(rate_adjustment, 2),
"adjusted_rate": round(adjusted_rate, 2)
}
Data Update Schedule
| Data Type | Update Day | Update Time |
|---|---|---|
| DOE Retail Diesel | Monday | ~5:00 PM ET |
| Historical (week prior) | Monday | ~5:00 PM ET |
OilPriceAPI updates diesel prices within 1 hour of the EIA release.
Getting Started
- Sign up at oilpriceapi.com/signup - free tier available
- Get your API key from the dashboard
- Test diesel endpoints with the examples above
- Build your surcharge calculator using our code samples
- Set up webhooks for automated updates
The free tier includes 1,000 API requests monthly—enough to build and test your fleet integration.
Frequently Asked Questions
How often is diesel price data updated?
Diesel prices are updated weekly, reflecting the EIA's Monday release schedule. OilPriceAPI processes and makes new prices available within 1 hour of the EIA publication. For most fleet applications, weekly granularity is sufficient since fuel surcharges typically update weekly or monthly.
What's the difference between DOE retail and wholesale diesel?
DOE retail diesel (what we provide) is the price at the pump including taxes. Wholesale/rack pricing is what fuel distributors pay before taxes and retail margin. Most fuel surcharge contracts reference DOE retail, which is the standard benchmark for trucking.
Can I get diesel prices for specific cities?
We provide PADD regional prices, which are the standard for freight contracts. City-specific prices (e.g., "Los Angeles diesel") vary by station and aren't published by the EIA. For city-specific needs, use the appropriate PADD region (California is separate from PADD 5).
How do I handle the one-week lag in DOE data?
DOE diesel prices reflect the prior week's average (Sunday to Saturday, released Monday). Most fleet contracts accommodate this lag since it's the industry standard. Ensure your fuel surcharge contracts specify "DOE retail diesel as published" to align with this timing.
What about non-US diesel prices?
Currently, OilPriceAPI focuses on US DOE diesel data. For international diesel, you can use our general refined products prices (HEATING_OIL_USD as a proxy) or contact us about international coverage.
Related Resources
- Fleet Management Solution - Complete fleet integration
- Logistics Fuel API - Supply chain applications
- Webhook Configuration - Automated price feeds
- API Reference - Complete endpoint documentation
- Gasoline Prices - Gas station applications