# Mexico Gas Prices API by Station (Official CNE) (`japan-open-data/mexico-fuel-station-prices`) Actor

Get today's gas prices at every Mexican gas station from the official CNE feed: regular, premium and diesel MXN/liter, permit number, coordinates, distance. For fleets, station owners and AI agents: sort by cheapest, area min/max/avg, no API key. JSON, CSV, API or MCP; $3 per 1,000 stations.

- **URL**: https://apify.com/japan-open-data/mexico-fuel-station-prices.md
- **Developed by:** [Japan Open Data](https://apify.com/japan-open-data) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 station rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Mexico Gas Prices API by Station (Official CNE Data)

**Get today's gas prices at every Mexican gas station near any point: regular (Magna), premium and diesel price per liter in MXN, with the station's CNE permit number, coordinates and distance.** The data is the official daily price feed of Mexico's energy regulator, the Comisión Nacional de Energía (CNE), covering about 13,800 stations nationwide. Search by latitude/longitude and radius, sort by nearest or cheapest, and optionally add one summary row with the minimum, maximum and average price of each fuel in the area — one flat JSON row per station, no API key needed.

- **Official data:** the prices that gas station permit holders report to the CNE (formerly the CRE — Comisión Reguladora de Energía), published daily. Open data under CC BY 4.0.
- **Precios de gasolina hoy por estación:** *gasolina Magna, Premium y diésel* for every *gasolinera* within your radius, in pesos per liter.
- **Cheapest gas near a location:** `sortBy: "price"` returns the cheapest stations first for the fuel you choose.
- **Area benchmark in one row:** `includeSummary: true` adds min / max / average per fuel for all stations within the radius — the "competitor price range" that gas station owners pay monitoring services for.
- **Pay only for results:** $3 per 1,000 station rows. "Nothing found" and error rows are free.

### What can you do with the Mexico Gas Prices API?

1. **Trucking, logistics and fleets.** Find the cheapest diesel around a depot or along a route, check fuel card receipts against the reported price, and pick refuelling stops. Run it once per stop (e.g. every 50–100 km) with `fuelType: "diesel"` and `sortBy: "price"`.
2. **Gas station owners and operators.** Monitor your competitors' prices every day: all stations within 3–10 km of your station with permit number, prices and distance, plus the local min / max / average in one summary row.
3. **Price comparison apps, analysts and AI agents.** Feed a map or a chatbot ("where is the cheapest premium near Guadalajara?"), compare regional fuel prices and inflation, or build your own daily price history by scheduling the Actor.

### How to use

1. Click **Start** with the default input: you get the 50 nearest stations within 5 km of central Mexico City (Zócalo).
2. Enter the **latitude and longitude** of your point (see common city centers below) and a **radius** in km.
3. Optionally choose a **fuel type** (regular, premium, diesel) and **sort by price** to get the cheapest stations first.
4. Turn on **Add a price summary row** to get the area's min / max / average prices.
5. Download the results as JSON, CSV or Excel, or call the Actor via API / MCP (see below). Use Apify **Schedules** to collect prices every day.

This Actor takes **coordinates, not addresses or city names** (the official feed has no address, state or city fields). Common centers: Mexico City `19.4326,-99.1332`, Guadalajara `20.6597,-103.3496`, Monterrey `25.6866,-100.3161`, Puebla `19.0414,-98.2063`, Tijuana `32.5149,-117.0382`, Querétaro `20.5888,-100.3899`, Mérida `20.9674,-89.5926`.

### Input

Only `latitude` and `longitude` are required, and both have defaults.

| Input | Type | Default | What it does |
|---|---|---|---|
| `latitude` | number | `19.4326` | Latitude of the search center (Mexico is about 14 to 33). |
| `longitude` | number | `-99.1332` | Longitude of the search center (negative in Mexico, about -118 to -86). |
| `radiusKm` | number | `5` | Only stations within this distance are returned (0.1–3000 km; 3000 covers all of Mexico). |
| `fuelType` | `any` / `regular` / `premium` / `diesel` | `any` | `any` = every station with at least one price. A specific fuel returns only stations that report it, and price sorting uses it. |
| `sortBy` | `distance` / `price` | `distance` | Nearest first, or cheapest first for the chosen fuel (regular when `fuelType` is `any`; stations without that price go last). |
| `maxResults` | integer | `50` | Maximum number of station rows (1–20,000). |
| `includeSummary` | boolean | `false` | Adds one `rowType: "summary"` row with station count and min / max / average price per fuel for **all** matching stations in the radius (not only the returned ones). |

#### Input example

The 3 cheapest stations for regular gasoline within 5 km of central Mexico City, plus the area summary:

```json
{
  "latitude": 19.4326,
  "longitude": -99.1332,
  "radiusKm": 5,
  "fuelType": "regular",
  "sortBy": "price",
  "maxResults": 3,
  "includeSummary": true
}
```

### Output

Real output from the input above (run on 2026-09-19; `source` shortened): one summary row and three station rows.

```json
{
  "status": "ok",
  "rowType": "summary",
  "searchLatitude": 19.4326,
  "searchLongitude": -99.1332,
  "radiusKm": 5.0,
  "fuelType": "regular",
  "stationCount": 96,
  "regularMin": 22.59, "regularMax": 24.49, "regularAvg": 23.73, "regularStationCount": 96,
  "premiumMin": 22.97, "premiumMax": 29.99, "premiumAvg": 28.8, "premiumStationCount": 94,
  "dieselMin": 26.87, "dieselMax": 27.19, "dieselAvg": 26.99, "dieselStationCount": 30,
  "currency": "MXN",
  "fetchedAt": "2026-09-19T04:47:43Z",
  "source": "Comisión Nacional de Energía (CNE), Mexico - Precios de expendio de gasolinas y diésel (datos.gob.mx, CC BY 4.0); ..."
}
```

```json
{
  "status": "ok",
  "rowType": "station",
  "placeId": "9985",
  "permitNumber": "PL/8939/EXP/ES/2015",
  "name": "CORPORACION GASOLINERA MILLENIUM SA DE CV",
  "holderType": "company",
  "latitude": 19.43856,
  "longitude": -99.119,
  "distanceKm": 1.63,
  "regularPrice": 22.59,
  "premiumPrice": 27.99,
  "dieselPrice": null,
  "currency": "MXN",
  "fetchedAt": "2026-09-19T04:47:43Z",
  "source": "Comisión Nacional de Energía (CNE), Mexico - Precios de expendio de gasolinas y diésel (datos.gob.mx, CC BY 4.0); ..."
}
```

| placeId | permitNumber | name | holderType | distanceKm | regular | premium | diesel |
|---|---|---|---|---|---|---|---|
| 9985 | PL/8939/EXP/ES/2015 | CORPORACION GASOLINERA MILLENIUM SA DE CV | company | 1.63 | 22.59 | 27.99 | null |
| 10893 | PL/3203/EXP/ES/2015 | CONSORCIO GASOLINERO PLUS SA DE CV | company | 1.666 | 22.59 | 27.99 | null |
| 8346 | PL/6363/EXP/ES/2015 | null | individual\_redacted | 4.586 | 22.77 | 22.97 | null |

Invalid input and searches with no stations return one **free** row that says what to change (real output):

```json
{"status": "not_found", "fetchedAt": "2026-09-19T04:36:43Z", "searchLatitude": 35.68, "searchLongitude": 139.76, "radiusKm": 5, "error": "No gas stations with reported prices within 5 km of 35.68,139.76; the point is outside Mexico; use Mexican coordinates (latitude about 14 to 33, longitude about -118 to -86, e.g. 19.4326,-99.1332 for Mexico City)."}
{"status": "error", "fetchedAt": "2026-09-19T04:36:25Z", "error": "\"fuelType\" must be one of: \"any\", \"regular\", \"premium\", \"diesel\"."}
```

#### Output fields

| Field | Meaning |
|---|---|
| `status` | `ok`, `not_found` or `error` |
| `rowType` | `station` (one gas station) or `summary` (area statistics, only with `includeSummary`) |
| `placeId` | Station ID in the CNE feed (stable, use it to track a station over time) |
| `permitNumber` | The station's CNE/CRE retail permit number (*permiso de expendio*, e.g. `PL/8939/EXP/ES/2015`) |
| `name` | Permit holder's name — **only for companies and organizations**, otherwise `null` (see Privacy) |
| `holderType` | `company` (name contains a legal form such as S.A. de C.V.) or `individual_redacted` (name removed) |
| `latitude`, `longitude` | Station coordinates |
| `distanceKm` | Straight-line distance from your search point (km) |
| `regularPrice`, `premiumPrice`, `dieselPrice` | Reported price per liter in MXN; `null` when the station does not report that fuel |
| `currency` | Always `MXN` (Mexican pesos, VAT included, as posted at the pump) |
| `fetchedAt` | When this Actor downloaded the feed (UTC). The feed has no per-price timestamp. |
| `source` | Data source, license and changes (attribution) |
| `searchLatitude`, `searchLongitude`, `radiusKm`, `fuelType`, `stationCount` | Summary / not\_found rows: the search and how many stations matched |
| `regularMin` … `dieselAvg`, `regularStationCount` … | Summary row: min / max / average price and number of stations with a price, per fuel |
| `error` | On `not_found` / `error` rows: one sentence explaining what to change |

### How much does it cost?

This Actor uses **Pay per event** pricing — you pay for results, not for compute time:

| Event | Price | When it is charged |
|---|---|---|
| Result row (`result-row`) | **$0.003** ($3 per 1,000 rows) | Each `ok` row: each station row, and the summary row when you ask for it |
| Actor start | **$0.001** | Once per run |

`not_found` and `error` rows are **free**.

| Example | Rows | Cost |
|---|---|---|
| Default run (50 nearest stations in central Mexico City) | 50 | about $0.15 |
| Cheapest 5 diesel stations near a truck stop | 5 | about $0.016 |
| Daily competitor check: 30 stations around your station + summary, every day for a month | 31 × 30 | about $2.82 / month |
| Area benchmark only (`maxResults: 1` + summary) | 2 | about $0.007 |

- Keep `maxResults` small when you only need the nearest or cheapest stations; the summary row already covers all stations in the radius.
- Set the **maximum cost per run** when you start the Actor to cap spending. If the limit is reached, the Actor stops cleanly and says so in the status message.

### Use via API / MCP (AI agents)

**Apify API (HTTP).** Run the Actor and get the rows in one call:

```bash
curl -X POST "https://api.apify.com/v2/acts/japan-open-data~mexico-fuel-station-prices/run-sync-get-dataset-items?token=<YOUR_APIFY_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"latitude": 20.6597, "longitude": -103.3496, "radiusKm": 10, "fuelType": "diesel", "sortBy": "price", "maxResults": 10}'
```

**Python (apify-client):**

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("japan-open-data/mexico-fuel-station-prices").call(run_input={
    "latitude": 25.6866, "longitude": -100.3161,  # Monterrey
    "radiusKm": 8, "fuelType": "premium", "sortBy": "price", "maxResults": 20, "includeSummary": True,
})
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(row["status"], row.get("rowType"), row.get("permitNumber"), row.get("premiumPrice"), row.get("distanceKm"))
```

**MCP (Claude, ChatGPT, Cursor and other AI agents).** Add this Actor as a tool through the Apify MCP server (https://mcp.apify.com), for example with `?tools=japan-open-data/mexico-fuel-station-prices`. An agent only needs `{"latitude": <lat>, "longitude": <lon>}`.

Recommended agent settings:

- "Cheapest diesel near X" → `{"latitude": .., "longitude": .., "radiusKm": 10, "fuelType": "diesel", "sortBy": "price", "maxResults": 5}`.
- "What do gas prices look like around X?" → `includeSummary: true` with a small `maxResults` (e.g. 5) — the summary row already has min / max / average.
- Convert an address or city to coordinates first; the Actor does not geocode.
- Always check `status`; on `not_found` / `error` show the `error` sentence to the user.

### FAQ

**How fresh are the prices?** The CNE updates the feed daily (around 18:00 Mexico City time). Every run downloads the current feed, so you always get the latest published prices; `fetchedAt` shows when.

**Can I search by city, state or address?** Not directly — the official feed only has coordinates. Use a city center from the list above, or geocode the address first.

**Can I get the station brand (Pemex, Oxxo Gas, …) or street address?** No. The feed has the permit holder and permit number, not the brand or address.

**Is it legal to use this data commercially?** Yes. The CNE publishes the data as open data under Creative Commons Attribution 4.0, which allows commercial use and adaptation with attribution. Each row's `source` field and the section below carry that attribution; keep it if you republish the data.

**Why do some stations have no name?** About 9% of permits belong to private persons. To avoid outputting personal names, only company and organization names are returned (see Privacy).

### Known limitations

- **Coordinates only.** No address, state or city search (not in the official feed) and no geocoding.
- **No station brand or address.** The feed has the permit holder, not the brand or street address.
- **Straight-line distance,** not driving distance.
- **Prices as reported.** Prices are reported by the stations; the CNE does not guarantee them, and the pump price can differ. A few values are far from the local average and are returned as reported.
- **Two diesel prices.** A few stations report diesel twice (probably regular diesel and ultra-low-sulfur DUBA diesel); the first valid price in the feed is used.
- **Mexico only.** Points outside Mexico return a free `not_found` row.
- **Cost limit.** If your maximum cost per run is lower than the price of one row, the dataset stays empty and the status message explains why.

### Data source and license

- **Source:** Comisión Nacional de Energía (CNE), Mexico — *Precios de expendio de gasolinas y diésel* (prices reported by permit holders under the regulator's agreement A/041/2018), public daily XML feeds linked from https://www.cne.gob.mx/ConsultaPrecios/GasolinasyDiesel/GasolinasyDiesel.html . The CNE's fuel price data is published as open data on datos.gob.mx (dataset "Petrolíferos", https://www.datos.gob.mx/dataset/petroliferos).
- **License:** Creative Commons Attribution 4.0 International (CC BY 4.0), https://creativecommons.org/licenses/by/4.0/ .
- **Changes made by this Actor:** the price and station feeds are joined by `place_id` (stations present in only one feed are dropped), stations are filtered by distance and fuel, placeholder prices (below 5 or above 100 MXN, e.g. `0.01`) are returned as `null`, names of permit holders who may be private persons are removed, and if a station reports the same fuel twice, the first valid price is used. Summary statistics are calculated by this Actor.
- **Not affiliated:** this Actor is an independent project and is **not affiliated with, endorsed by or sponsored by the CNE, the CRE or the Government of Mexico**.
- **Access:** one run downloads the two public feeds once (about 6 MB in total) and identifies itself in the User-Agent.

### Privacy

About 9% of stations are held by private persons (individual permit holders). To avoid outputting personal names, `name` is only returned when it contains a company or organization legal form (S.A. de C.V., S.A., S. de R.L., S.A.P.I., S.A.B., S.C., S.P.R. de R.L., cooperatives, "sin tipo de sociedad" public bodies, …; case, dot and spacing variants included). All other stations get `name: null` and `holderType: "individual_redacted"` — this may also hide a few organizations whose registered name has no legal form. Permit number, coordinates and prices describe the business location and are always returned.

### More from Japan Open Data

- [US Hail History by Location (NOAA NEXRAD Radar)](https://apify.com/japan-open-data/us-hail-history) — every hail day near any U.S. latitude/longitude with max estimated hail size, from NOAA NEXRAD radar.
- [TSA Checkpoint Travel Numbers (Daily, Weekly & YoY)](https://apify.com/japan-open-data/tsa-checkpoint-throughput) — daily U.S. TSA airport checkpoint traveler counts as clean JSON, with weekly averages and year-over-year change.
- [Japan Postal Code & Address in English](https://apify.com/japan-open-data/japan-postal-code-english) — look up Japanese postal codes and addresses in English/romaji, kanji and kana, from Japan Post's official data.
- [US Storm Reports API: Hail, Wind & Tornado (NWS)](https://apify.com/japan-open-data/us-storm-reports-live) — U.S. hail, wind, tornado and flood reports from official NWS Local Storm Reports within hours (last 7 days), filterable by state or radius.

### Feedback

Found a wrong value or need another field (e.g. brand, state, route search)? Open an issue on the Actor's **Issues** tab with your input and what you expected.

# Actor input Schema

## `latitude` (type: `number`):

Latitude of the search center in decimal degrees (Mexico is about 14 to 33). Default: Mexico City, 19.4326.

## `longitude` (type: `number`):

Longitude of the search center in decimal degrees; Mexican longitudes are negative (about -118 to -86). Default: Mexico City, -99.1332.

## `radiusKm` (type: `number`):

Only gas stations within this distance of the point are returned (0.1 to 3000 km; 3000 covers all of Mexico).

## `fuelType` (type: `string`):

"any" returns every station with at least one reported price; "regular" (Magna, 87 octane), "premium" (91+ octane) or "diesel" returns only stations that report that fuel. Price sorting uses this fuel (regular when "any").

## `sortBy` (type: `string`):

"distance" = nearest first; "price" = cheapest first for the selected fuel (regular when fuel type is "any"; stations without that price go last).

## `maxResults` (type: `integer`):

Maximum number of station rows to return (1 to 20000).

## `includeSummary` (type: `boolean`):

Adds one extra row (rowType "summary") with the number of stations and the minimum, maximum and average price of each fuel within the radius (all matching stations, not only the returned ones).

## Actor input object example

```json
{
  "latitude": 19.4326,
  "longitude": -99.1332,
  "radiusKm": 5,
  "fuelType": "any",
  "sortBy": "distance",
  "maxResults": 50,
  "includeSummary": false
}
```

# Actor output Schema

## `results` (type: `string`):

Prices in MXN per liter, permit number, coordinates and distance per station. Table view: overview.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "latitude": 19.4326,
    "longitude": -99.1332
};

// Run the Actor and wait for it to finish
const run = await client.actor("japan-open-data/mexico-fuel-station-prices").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "latitude": 19.4326,
    "longitude": -99.1332,
}

# Run the Actor and wait for it to finish
run = client.actor("japan-open-data/mexico-fuel-station-prices").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "latitude": 19.4326,
  "longitude": -99.1332
}' |
apify call japan-open-data/mexico-fuel-station-prices --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,japan-open-data/mexico-fuel-station-prices"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/LVlxK9inbgedGkdYQ/builds/lhE4SzcrKoOAf72kW/openapi.json
