
You need to determine a vehicle’s fuel type from a VIN and wire it into your backend safely. By the end of this guide you’ll be able to call the Vehicle API VIN decoding endpoint server-side, read fuel_type and engine.fuel, handle errors and nulls, and cache results for speed and cost control.
What you get when you decode a VIN for fuel
The VIN decode endpoint returns a normalized fuel_type at the top level and a detailed engine.fuel field inside the engine object. These are derived from NHTSA vPIC data and work worldwide for 17-character VINs, with the fullest detail on US-market vehicles. Fields not published by NHTSA come back as null. This is not a vehicle history report—there is no title, ownership, or accident history.
- fuel_type: high-level string like Gasoline, Diesel, Flex Fuel, etc.
- engine.fuel: engine-level fuel descriptor aligned with fuel_type.
- EV/hybrid-specific keys (electrification_level, battery_kwh, charger_level, etc.) are present but null for gasoline vehicles.
US safety datasets (recalls, owner complaints, NCAP ratings) are available in the platform but apply only to US-market vehicles and are matched by make, model, and year. Dutch plate lookups (from RDW open data) never include a VIN. Explore the platform at vehicles-api.com.
Endpoint and authentication
Base URL: https://vehicles-api.com/api/v1
VIN decode (fuel type is part of this response): POST https://vehicles-api.com/api/v1/vin/decode
- Auth: send your API key using header X-API-Key: YOUR_API_KEY. Authorization: Bearer YOUR_API_KEY also works.
- Request body: JSON object with a single key vin for a 17-character VIN.
- Response envelope: Every response includes status and source. On success, data is populated. On errors, status is error and error.code and error.message are provided.
Important: Keep calls on the server. Do not ship your API key in browser code.
cURL example
This is the official sample using the control VIN (a 2003 Honda Accord). Copy and run it server-side, replacing YOUR_API_KEY with your key.
curl -X POST "https://vehicles-api.com/api/v1/vin/decode" -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{"vin":"1HGCM82633A004352"}'
Official JSON response
Note the top-level fuel_type and engine.fuel fields. This control VIN is a gasoline car, so EV and hybrid fields are null by design.
{
"status": "success",
"source": "nhtsa",
"data": {
"vin": "1HGCM82633A004352",
"valid": true,
"year": 2003,
"make": "HONDA",
"model": "Accord",
"trim": "EX-V6",
"body": "Coupe",
"doors": 2,
"vehicle_type": "PASSENGER CAR",
"engine": {
"cylinders": 6,
"displacement_l": 3,
"configuration": "V-Shaped",
"model": "J30A4",
"hp": 240,
"fuel": "Gasoline"
},
"fuel_type": "Gasoline",
"electrification_level": null,
"ev_drive_unit": null,
"battery_kwh": null,
"charger_level": null,
"charger_power_kw": null,
"drive": null,
"transmission": {
"style": "Automatic",
"speeds": 5
},
"plant": {
"country": "UNITED STATES (USA)",
"city": "MARYSVILLE",
"state": "OHIO"
},
"manufacturer": "AMERICAN HONDA MOTOR CO., INC."
}
}
Fields you will actually use
- status: "success" or "error". Gate your logic on this.
- source: "nhtsa" for VIN decoding data provenance.
- data.vin: Echo of the requested VIN; useful as a cache key.
- data.valid: Boolean validity of the VIN structure.
- data.fuel_type: High-level fuel description to show in UI or store for filtering.
- data.engine.fuel: Engine-level fuel; often the same as fuel_type but keep both to support nuanced cases.
- data.engine.cylinders, displacement_l, hp: Commonly displayed alongside fuel.
- data.electrification_level, battery_kwh, charger_level, charger_power_kw: Present but null for gasoline in this example; check for nulls before using.
Nullability: If a field is not provided by NHTSA for the VIN’s market, it will be null. Always null-check optional keys before rendering or persisting.
Python (requests) server-side integration
This example posts the VIN as JSON, enforces a timeout, and handles the response envelope. It demonstrates how to read fuel_type and engine.fuel, and how to handle an error with error.code and error.message. Keep your API key in server-side config or a secret manager.
import os
import requests
API_BASE = "https://vehicles-api.com/api/v1"
API_KEY = os.environ.get("VEHICLES_API_KEY") # do not hardcode in source
TIMEOUT_S = 8.0
def decode_vin_fuel(vin: str) -> dict:
url = f"{API_BASE}/vin/decode"
headers = {
"X-API-Key": API_KEY,
"Content-Type": "application/json",
# Alternatively: "Authorization": f"Bearer {API_KEY}",
}
try:
resp = requests.post(url, json={"vin": vin}, headers=headers, timeout=TIMEOUT_S)
except requests.RequestException as e:
raise RuntimeError(f"request_failed: {e}") from e
# The API always returns an envelope with status and either data or error
try:
payload = resp.json()
except ValueError:
raise RuntimeError(f"invalid_json: HTTP {resp.status_code}")
status = payload.get("status")
if status != "success":
err = payload.get("error") or {}
code = err.get("code", "unknown_error")
message = err.get("message", "No message")
raise RuntimeError(f"{code}: {message}")
data = payload.get("data") or {}
# Extract the fields you care about
fuel_type = data.get("fuel_type") # e.g., "Gasoline" or None
engine = data.get("engine") or {}
engine_fuel = engine.get("fuel") # e.g., "Gasoline" or None
# Keep both available to callers
return {
"vin": data.get("vin"),
"valid": data.get("valid"),
"fuel_type": fuel_type,
"engine_fuel": engine_fuel,
"cylinders": engine.get("cylinders"),
"displacement_l": engine.get("displacement_l"),
"hp": engine.get("hp"),
"electrification_level": data.get("electrification_level"), # may be null
}
if __name__ == "__main__":
result = decode_vin_fuel("1HGCM82633A004352")
print(result)
Notes:
- Use json= for POST bodies, as shown.
- Always set a timeout to avoid hanging connections.
- Treat any non-"success" status as an error and surface error.code and error.message to logging.
- Cache results by VIN; see the caching section below.
PHP (cURL) server-side integration
This snippet posts the VIN, uses a short timeout, and decodes the JSON envelope. It extracts fuel_type and engine.fuel and raises an exception if status is error.
<?php
$apiBase = "https://vehicles-api.com/api/v1";
$apiKey = getenv("VEHICLES_API_KEY"); // store securely; do not expose in client code
$vin = "1HGCM82633A004352";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiBase . "/vin/decode",
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"X-API-Key: " . $apiKey,
"Content-Type: application/json",
// Alternatively: "Authorization: Bearer " . $apiKey,
],
CURLOPT_POSTFIELDS => json_encode(["vin" => $vin]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 8,
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException("request_failed: " . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Parse the envelope
$payload = json_decode($response, true);
if (!is_array($payload)) {
throw new RuntimeException("invalid_json: HTTP " . $httpCode);
}
if (($payload["status"] ?? null) !== "success") {
$err = $payload["error"] ?? [];
$code = $err["code"] ?? "unknown_error";
$message = $err["message"] ?? "No message";
throw new RuntimeException($code . ": " . $message);
}
$data = $payload["data"] ?? [];
$fuelType = $data["fuel_type"] ?? null;
$engineFuel = $data["engine"]["fuel"] ?? null;
echo json_encode([
"vin" => $data["vin"] ?? null,
"fuel_type" => $fuelType,
"engine_fuel" => $engineFuel,
], JSON_PRETTY_PRINT), PHP_EOL;
Keep this code on the server. Never embed your key in frontend or mobile apps.
Response envelope, errors, and nulls
Every response from the endpoint uses the same envelope:
- Success: {"status":"success","source":"nhtsa","data":{...}}
- Error: {"status":"error","error":{"code":"...","message":"..."}}
Implementation tips:
- Check status first. If it is error, read error.code and error.message and decide whether to retry, back off, or surface a message to the user.
- Null fields are expected for attributes not published by the source. Do not convert nulls to empty strings; keep them as nulls in your storage or explicitly map them to your system’s notion of “unknown”.
- The source field lets you trace provenance for auditing or support.
Coverage notes and what not to expect
- VIN decoding works worldwide for 17-character VINs. Data is typically fullest for US-market vehicles.
- US safety datasets (recall campaigns, owner complaints, NCAP crash ratings) are US-market only and matched by make, model, and year.
- Dutch plates come from RDW open data. They do not include a VIN.
- This is not a vehicle history report. No title/ownership/accident history is provided.
For platform-wide details and additional endpoints, see the Documentation and visit vehicles-api.com.
Caching decoded VINs for speed and cost
VINs are immutable identifiers for a manufactured vehicle. Once decoded, fields like year, make, model, trim, engine, transmission, and especially fuel_type do not change. Cache aggressively:
- Key: the 17-character VIN string (uppercase).
- Value: the full JSON data or a compact projection including fuel_type and engine.fuel.
- TTL: long (e.g., months). In practice, VIN decode data is static; you can treat it as effectively permanent unless you rebuild indexes.
- Invalidate: only when you detect a decoding schema update in your system or re-normalize fields.
Caching reduces latency and API usage, helping stay within your monthly quota and rate limits.
Rate limits, monthly quota, and retries
Vehicle API enforces plan-based quotas and rate limits. When you exceed limits, the response will use the standard error envelope with error.code and error.message describing the condition. Implement the following:
- Backoff: On transient errors, back off and retry with jitter. Respect any guidance provided in error.message.
- Idempotency: VIN decoding is idempotent; safe to retry the same VIN.
- Monitoring: Track error.code occurrences over time to spot throttling patterns.
- Caching-first: Check your cache before calling the API to minimize request volume.
Plan pricing starts at $19/month and every plan includes a 7-day free trial. For current quotas and limits, refer to the Documentation.
Production tips for fuel data consumers
- Normalize display: Prefer fuel_type in UI; keep engine.fuel for power users and audits.
- Null handling: For EV/hybrid fields, guard against nulls. Only display when non-null.
- Search filters: Use fuel_type for marketplace or dealer filters (e.g., Gasoline, Diesel).
- Fleet policy: For insurance or fleet scoring, persist both fuel_type and engine specs (cylinders, displacement_l, hp) for repeatable analysis.
- Audit trail: Persist source to document where the decode came from.
MCP server for agents and tools
If you are building AI agents or tools that need the same VIN fuel decoding via MCP, use the Vehicle API MCP server at MCP. It exposes the same underlying data model through the MCP protocol, suitable for tool-enabled LLM workflows.
Testing checklist
- Verify your server includes X-API-Key and uses a timeout.
- Confirm the body is JSON: {"vin":"..."} and not form-encoded.
- Ensure you check status before reading data and capture error.code and error.message on failures.
- Write unit tests for null handling of electrification-related fields.
- Add an integration test that asserts fuel_type equals engine.fuel when both are present.
- Measure and log cache hit rate and API latency.
FAQ
Does VIN decoding work outside the US?
Yes. The endpoint decodes any 17-character VIN worldwide, with the most complete coverage for US-market vehicles. Fields not published by NHTSA will be null.
Will I get recall campaigns and crash ratings with this call?
No. This VIN decode call returns specs such as fuel_type and engine details. US safety datasets (recalls, owner complaints, NCAP crash ratings) are available on the platform but are US-market only and matched by make, model, and year.
Why are electrification fields null for my result?
If the vehicle is not a hybrid or EV, electrification_level, battery_kwh, charger_level, and charger_power_kw will be null. Always null-check before displaying.
Can I call this endpoint from the browser?
Do not expose your API key in browser or mobile code. Call the API from your server and forward only the data you need to your clients.
How should I cache results?
Cache by VIN. VIN decode data is static; use a long TTL and invalidate only when your internal schema changes. This reduces latency and helps you stay within rate limits and monthly quota.
Ready to ship a fuel-type lookup into your app? Start your 7-day free trial and get an API key: Register. For platform details, visit vehicles-api.com and browse the Documentation.