DEV Community

Cover image for Gas Prices API: How to Get Live Per-Station Fuel Prices by ZIP Code in 2026
Truffle Pig Data
Truffle Pig Data

Posted on

Gas Prices API: How to Get Live Per-Station Fuel Prices by ZIP Code in 2026

Fuel price data has a coverage gap that annoys me every time I hit it. Government sources like the EIA's weekly gasoline report publish clean averages by region, but averages will not tell you what the station on the corner charges today. The per-station numbers live inside consumer apps that were built for thumbs, not code. The Fuel Prices API on Apify closes that gap: give it a ZIP, a city, or GPS coordinates and it returns live per-station prices as JSON.

Disclosure: the Apify links in this post are affiliate links. If you run the Actor, I may earn a referral commission at no extra cost to you.

Is there a gas prices API?

Not really, and the alternatives each miss. Official data is aggregated: weekly averages by state or metro, useful for trend charts and useless for "where should this truck refuel". The consumer apps that do have per-station prices offer no public developer API. So a gas prices API in practice means a scraper you call like an API: location in, station-level prices out, priced per result.

What the gas prices API returns

The gas prices API returns live per-station retail fuel prices for a US location as structured JSON: station name, address, distance, ratings, and separate cash and credit prices with the time each was posted.

Field Example Notes
name "Costco" Station name
price_cash, price_credit 2.89, 2.99 Separate cash and credit prices
price_cash_postedTime recency of the posting Same for credit, so you can judge freshness
address_line1, address_locality, address_region, address_postalCode "1000 Main St", "Austin", "TX", "78701" Full mailing address
distance from your search point Handy for routing decisions
starRating, ratingsCount 4.5, 312 Station ratings

Coverage is US-primary with some Canada. The fuel input picks the grade: 1 Regular, 2 Midgrade, 3 Premium, 4 Diesel, 5 E85, 12 Unleaded 88.

Who this is for

Fleet and logistics people costing routes by real pump prices, developers building comparison or trip-planning apps, and analysts watching local price moves that state averages smooth away.

The manual way, and where it breaks

The DIY approach scrapes a consumer fuel app's website. It goes badly in the usual ways: the pages are session-heavy, the station list renders through JavaScript keyed to a map view, and the markup changes with the app's release cycle. Geosearch is the hard part; reverse-engineering how a ZIP becomes a station list is brittle work, and once you automate it at any volume you get blocked. The Actor's whole pitch is skipping that: no cookies, no sessions, pay per result.

The faster way: run the fuel prices scraper

Apify Console

  1. Open the Fuel Prices API and click Try for free.
  2. Set search to a ZIP, city, or GPS coordinates, and pick a fuel grade.
  3. Run it and download the dataset as JSON, CSV, or Excel.

REST

curl -X POST "https://api.apify.com/v2/acts/johnvc~fuelprices/runs?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "search": "Austin, TX", "fuel": 4 }'
Enter fullscreen mode Exit fullscreen mode

Run endpoint reference: the Apify API docs.

Get fuel prices in Python

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")

run = client.actor("johnvc/fuelprices").call(
    run_input={"search": "78701", "fuel": 1}
)

for station in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(station["name"], station["address_locality"], station["price_cash"], station["price_credit"])
Enter fullscreen mode Exit fullscreen mode

Sort by price_cash and you have the cheapest-gas answer for any neighborhood in a few lines.

Get live gas prices for any US city

The task Find live gas prices in any US city by fuel type is the general recipe, and there are prefilled city versions ready to run, including Austin, Chicago, and New York, with eleven major metros covered in total.

Look up gas prices by ZIP code

Find gas station prices by ZIP code is the tightest version of the search: one ZIP in, every nearby station with cash and credit prices out.

Search near GPS coordinates

For routing software, Find gas prices near GPS map coordinates accepts raw coordinates, so a waypoint on a route can become a refuel decision without a geocoding step.

Diesel prices from Claude and other MCP clients

The diesel task set was built for MCP use: ask Claude for diesel prices in a metro and the Actor answers with live stations. There are prefilled examples for Austin, Dallas, and Los Angeles, among the same eleven metros. Connect through the Apify MCP server (https://mcp.apify.com/?tools=actors,docs,johnvc/fuelprices) in Claude, Claude Code, or Cursor, and read more about Claude at claude.ai.

FAQ about scraping gas prices

What does the fuel prices scraper cost to run?

You pay per result returned, with no setup fee, no minimums, and no subscription. Small searches cost small money, and new Apify accounts include free platform credit, so a first ZIP-code lookup is effectively free to try.

Is this scraper a GasBuddy API alternative?

For developers, yes, that is the role it fills. GasBuddy is a consumer app without a public developer API, and this Actor returns the same kind of per-station data (name, address, cash and credit price, ratings) as JSON you can actually build on.

Can Claude fetch fuel prices through this scraper?

Yes. Add the Apify MCP server and the scraper becomes a callable tool, which is exactly what the diesel-by-MCP task series demonstrates city by city.

Can I schedule the scraper to monitor prices across ZIP codes?

Yes. Save one task per ZIP or city, attach an Apify Schedule, and let runs accumulate; that is how you build the price history that does not exist anywhere else. Start from the Fuel Prices API.

Does the scraper return historical prices or state averages?

No, and this is the honest limit: it returns live per-station prices only. No historical time series, no national or state averages, no brand filter. Each price carries its posted time so you can judge freshness, and history exists once you schedule runs and keep the output.

More from Truffle Pig Data

Same Actor, other angles: how to get live gas price data via API on Medium, the Fuel Prices API write-up on LinkedIn, and live gas prices by ZIP, city, or GPS on Peerlist.

Wrapping up

Averages are for charts; per-station prices are for decisions. Point the Fuel Prices API at your ZIP and see what comes back.

Top comments (0)