# Fuel economy

The EPA (fueleconomy.gov) configuration matching the decode: MPG or MPGe, range, annual fuel cost, CO2. `match` says how exactly the configuration was singled out.

## Endpoint

```
GET https://api.motorsdynamic.com/api/v2/fuel/{vin}
```

## Plan and price

| Plan | Access | Price |
| --- | --- | --- |
| Free | Yes | included in the 1,000 monthly calls |
| Growth | Yes | $0.0015 per call |
| Scale | Yes | $0.0009 per call |
| Enterprise | Yes | contract |

A call is billed when it answers 2xx. See [pricing](https://developers.motorsdynamic.com/pricing.md).

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `vin` | path | string | yes | 17-character VIN (case-insensitive). |

## Example request

curl:

```bash
curl "https://api.motorsdynamic.com/api/v2/fuel/1HGCM82633A004352" \
  -H "x-api-key: $MD_API_KEY"
```

JavaScript:

```javascript
const res = await fetch("https://api.motorsdynamic.com/api/v2/fuel/1HGCM82633A004352", {
  headers: { "x-api-key": process.env.MD_API_KEY },
});
if (!res.ok) throw new Error(`${res.status} ${(await res.json()).error}`);
const data = await res.json();
console.log(data);
```

Python:

```python
import os, requests

res = requests.get(
    "https://api.motorsdynamic.com/api/v2/fuel/1HGCM82633A004352",
    headers={"x-api-key": os.environ["MD_API_KEY"]},
    timeout=10,
)
res.raise_for_status()
print(res.json())
```

## Response fields

| Field | Type | Description |
| --- | --- | --- |
| `meta` | object |  |
| `data` | object |  |
| `data.vin` | string |  |
| `data.vehicle` | object |  |
| `data.vehicle.year` | integer or null |  |
| `data.vehicle.make` | string or null |  |
| `data.vehicle.model` | string or null |  |
| `data.vehicle.trim` | string or null |  |
| `data.available` | boolean | false when EPA does not list the model. |
| `data.epa` | object or null |  |
| `data.epa.epa_id` | integer |  |
| `data.epa.model` | string |  |
| `data.epa.vehicle_class` | string or null |  |
| `data.epa.transmission` | string or null |  |
| `data.epa.drive` | string or null |  |
| `data.epa.cylinders` | integer or null |  |
| `data.epa.displacement_l` | number or null |  |
| `data.epa.fuel_type` | string or null |  |
| `data.epa.electrification` | string or null |  |
| `data.mpg` | object or null |  |
| `data.mpg.city` | integer or null |  |
| `data.mpg.highway` | integer or null |  |
| `data.mpg.combined` | integer or null |  |
| `data.mpg.unit` | `mpg` or `mpge` |  |
| `data.alternative` | object or null |  |
| `data.alternative.fuel_type` | string or null |  |
| `data.alternative.city` | integer or null |  |
| `data.alternative.highway` | integer or null |  |
| `data.alternative.combined` | integer or null |  |
| `data.alternative.unit` | `mpg` or `mpge` |  |
| `data.range_miles` | integer or null |  |
| `data.electric_range_miles` | integer or null |  |
| `data.charge_hours_240v` | number or null |  |
| `data.annual_fuel_cost` | object or null |  |
| `data.annual_fuel_cost.amount` | number |  |
| `data.annual_fuel_cost.currency` | string |  |
| `data.annual_fuel_cost.estimate` | `true` |  |
| `data.annual_fuel_cost.terms` | object |  |
| `data.five_year_savings_vs_average` | integer or null |  |
| `data.emissions` | object or null |  |
| `data.emissions.co2_grams_per_mile` | number or null |  |
| `data.emissions.ghg_score` | integer or null |  |
| `data.emissions.fuel_economy_score` | integer or null |  |
| `data.match` | object or null |  |
| `data.match.quality` | `exact` or `narrowed` or `model` |  |
| `data.match.configurations` | integer |  |
| `data.match.matched_on[]` | array of fuel or drive or cylinders or displacement or trim |  |
| `data.match.mpg_combined_range` | object or null |  |
| `data.freshness` | object |  |
| `data.freshness.loaded_at` | string or null |  |
| `data.freshness.source_modified_on` | string or null |  |
| `data.provenance` | object |  |
| `data.provenance.source` | `epa_fueleconomy` |  |
| `data.provenance.source_url` | string |  |

## Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_parameter` | A parameter is missing or malformed. The message names it. |
| 401 | `invalid_api_key` | The key is missing, revoked or mistyped. |
| 403 | `not_entitled` | The key may not read this dealer or source. |
| 404 | `not_found` | Nothing matches the identifier in the path. |
| 429 | `rate_limited or quota_exceeded` | Slow down (see `Retry-After`), or the Free monthly calls are used up. |
| 504 | `query_timeout` | The query passed its 4 second budget. Narrow the filters. Not billed. |

Every error has the same body: `{ "error": "<code>", "message": "..." }`. Full list: [errors](https://developers.motorsdynamic.com/docs/errors.md).
