# VIN decoding

> POST /vin decodes a Vehicle Identification Number: check digit, region and model year locally, plus make, model, trim, body, engine and plant from NHTSA vPIC.

`POST https://api.qelka.com/v1/vin`

Decode a Vehicle Identification Number (VIN) to learn whether it is well formed, where and when the vehicle was made, and its make, model, trim, body, engine and assembly plant. Each lookup costs 1 credit, valid or not; errors and test keys are never billed.

## Request

Send the 17-character VIN. The structure, check digit, region and model year are decoded on our servers; the vehicle details come from vPIC, the decoder of the U.S. National Highway Traffic Safety Administration (NHTSA).

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `vin` | string | Yes | none | The VIN, 1 to 40 characters before spaces and hyphens are removed. Lower case is accepted. |
| `fresh` | boolean | No | `false` | `true` skips the 30-day result cache and asks vPIC again. |

The call waits for vPIC, so every snippet sets a 30-second client timeout.

```bash title="cURL"
curl https://api.qelka.com/v1/vin \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"vin": "1HGCM82633A004352"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/vin', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ vin: '1HGCM82633A004352' }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/vin",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"vin": "1HGCM82633A004352"},
    timeout=30,
)
result = response.json()
print(result)
```
```php title="PHP"
<?php
$ch = curl_init('https://api.qelka.com/v1/vin');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('QELKA_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['vin' => '1HGCM82633A004352']),
    CURLOPT_TIMEOUT => 30,
]);
$result = json_decode(curl_exec($ch), true);
print_r($result);
```
```go title="Go"
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	payload, _ := json.Marshal(map[string]any{"vin": "1HGCM82633A004352"})
	request, _ := http.NewRequest(http.MethodPost, "https://api.qelka.com/v1/vin", bytes.NewReader(payload))
	request.Header.Set("Authorization", "Bearer "+os.Getenv("QELKA_API_KEY"))
	request.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
		panic(err)
	}
	fmt.Println(result)
}
```
```ruby title="Ruby"
require 'json'
require 'net/http'

uri = URI('https://api.qelka.com/v1/vin')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV.fetch('QELKA_API_KEY')}"
request['Content-Type'] = 'application/json'
request.body = JSON.generate({ vin: '1HGCM82633A004352' })

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 30) do |http|
  http.request(request)
end
result = JSON.parse(response.body)
puts result
```

## Response

Every VIN gets a `200`, valid or not. Read `valid` first; `vehicle` is filled when vPIC knows the vehicle.

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup: `lkp_` followed by 26 characters. |
| `object` | string | Always `vin`. |
| `input` | string | The `vin` you sent, without surrounding spaces. |
| `valid` | boolean | `true` when the VIN has 17 allowed characters and, for North American manufacturers, a correct check digit. |
| `status` | string | `valid` or `invalid`. |
| `reason` | string or null | `invalid_length`, `invalid_characters` or `invalid_check_digit`. `null` when the VIN is valid. |
| `vin` | string or null | The VIN, upper case, without separators. `null` when it is not 17 characters long. |
| `wmi` | object or null | World Manufacturer Identifier. `null`, like `vds`, `vis`, `check_digit`, `model_year`, `plant_code` and `serial_number`, when the VIN is not 17 allowed characters. |
| `wmi.code` | string | Positions 1 to 3. |
| `wmi.region` | string | `africa`, `asia`, `europe`, `north_america`, `oceania` or `south_america`, from the first character: `A` to `H` Africa, `J` to `R` Asia, `S` to `Z` Europe, `1` to `5` North America, `6` and `7` Oceania, `8`, `9` and `0` South America (ISO 3780 zones). |
| `wmi.small_manufacturer` | boolean | `true` when the third character is `9`: small manufacturers share the code and are told apart by positions 12 to 14. |
| `vds` | string or null | Vehicle Descriptor Section: positions 4 to 8, chosen by the manufacturer to describe the model. |
| `vis` | string or null | Vehicle Identifier Section: positions 10 to 17. |
| `check_digit` | object or null | The check digit at position 9. |
| `check_digit.value` | string | Position 9 as written. |
| `check_digit.expected` | string | The check digit computed from the 16 other characters. |
| `check_digit.valid` | boolean | `true` when `value` equals `expected`. |
| `check_digit.required` | boolean | `true` for North American manufacturers, which must use the check digit. |
| `model_year` | object or null | The model year read from position 10. |
| `model_year.code` | string | Position 10. |
| `model_year.candidates` | array of integers | The years the code stands for, up to next year's models. |
| `model_year.estimate` | integer or null | The most likely year: from position 7 for North American manufacturers, else the latest candidate. |
| `plant_code` | string or null | Position 11: the assembly plant code of North American manufacturers. |
| `serial_number` | string or null | Positions 12 to 17. |
| `vehicle` | object or null | What NHTSA vPIC decodes. `null` when vPIC has no make, model or year for the VIN, or was not asked because the VIN is not 17 allowed characters. Each field inside is `null` when vPIC has no value. |
| `vehicle.make` | string or null | Make, such as `HONDA`. |
| `vehicle.model` | string or null | Model, such as `Accord`. |
| `vehicle.model_year` | integer or null | Model year as NHTSA decodes it. Prefer it to `model_year.estimate` when both exist. |
| `vehicle.trim` | string or null | Trim level. |
| `vehicle.series` | string or null | Series. |
| `vehicle.body_class` | string or null | Body class, such as `Coupe`. |
| `vehicle.vehicle_type` | string or null | Vehicle type, such as `PASSENGER CAR`. |
| `vehicle.doors` | integer or null | Number of doors. |
| `vehicle.drive_type` | string or null | Drive type. |
| `vehicle.fuel_type` | string or null | Primary fuel type. |
| `vehicle.engine` | object | Engine details. |
| `vehicle.engine.cylinders` | integer or null | Number of cylinders. |
| `vehicle.engine.displacement_l` | number or null | Displacement in litres, rounded to one decimal. |
| `vehicle.engine.horsepower` | number or null | Engine power in horsepower. |
| `vehicle.engine.configuration` | string or null | Engine configuration, such as `V-Shaped`. |
| `vehicle.engine.model` | string or null | Engine model code. |
| `vehicle.transmission` | object | Transmission details. |
| `vehicle.transmission.style` | string or null | Transmission style, such as `Automatic`. |
| `vehicle.transmission.speeds` | integer or null | Number of speeds. |
| `vehicle.manufacturer` | string or null | Manufacturer name as filed with NHTSA. |
| `vehicle.plant` | object | Assembly plant. |
| `vehicle.plant.city` | string or null | Plant city. |
| `vehicle.plant.state` | string or null | Plant state. |
| `vehicle.plant.country` | string or null | Plant country. |
| `vehicle.plant.company` | string or null | Plant company name, as vPIC lists it. |
| `vehicle.gvwr` | string or null | Gross vehicle weight rating class, as vPIC writes it. |
| `nhtsa` | object or null | vPIC's own decoding notes. `null` when vPIC was not asked or returned nothing. |
| `nhtsa.error_codes` | array of strings | vPIC decoding codes. `0` means the VIN decoded clean; other codes flag a wrong check digit, an incomplete decode or an unknown manufacturer. |
| `nhtsa.message` | string or null | vPIC's explanation of the codes. |
| `credits_used` | integer | Credits debited for this call: 1 with a live key, `0` with a test key. |
| `cached` | boolean | `true` when the answer came from the 30-day cache. |

```json title="Response"
{
  "id": "lkp_01M85RBTDRPFW1TC1KY1CSMHRJ",
  "object": "vin",
  "input": "1HGCM82633A004352",
  "valid": true,
  "status": "valid",
  "reason": null,
  "vin": "1HGCM82633A004352",
  "wmi": { "code": "1HG", "region": "north_america", "small_manufacturer": false },
  "vds": "CM826",
  "vis": "3A004352",
  "check_digit": { "value": "3", "expected": "3", "valid": true, "required": true },
  "model_year": { "code": "3", "candidates": [2003], "estimate": 2003 },
  "plant_code": "A",
  "serial_number": "004352",
  "vehicle": {
    "make": "HONDA",
    "model": "Accord",
    "model_year": 2003,
    "trim": "EX-V6",
    "series": null,
    "body_class": "Coupe",
    "vehicle_type": "PASSENGER CAR",
    "doors": 2,
    "drive_type": null,
    "fuel_type": "Gasoline",
    "engine": { "cylinders": 6, "displacement_l": 3, "horsepower": 240, "configuration": "V-Shaped", "model": "J30A4" },
    "transmission": { "style": "Automatic", "speeds": 5 },
    "manufacturer": "AMERICAN HONDA MOTOR CO., INC.",
    "plant": { "city": "MARYSVILLE", "state": "OHIO", "country": "UNITED STATES (USA)", "company": null },
    "gvwr": "Class 1C: 4,001 - 5,000 lb (1,814 - 2,268 kg)"
  },
  "nhtsa": {
    "error_codes": ["0"],
    "message": "0 - VIN decoded clean. Check Digit (9th position) is correct"
  },
  "credits_used": 1,
  "cached": false
}
```

## Act on the result

| `status` | `reason` | What it means | What to do |
|---|---|---|---|
| `valid` | `null` | 17 allowed characters and, for a North American manufacturer, a correct check digit. | Use `vehicle` when it is filled. When it is `null`, the VIN is well formed but vPIC does not know the vehicle. |
| `invalid` | `invalid_length` | Not 17 characters once spaces and hyphens are removed. | Ask for the VIN again. |
| `invalid` | `invalid_characters` | A character VINs never use: `I`, `O`, `Q`, or anything other than letters and digits. | Ask for the VIN again: an `O` is probably a `0`, an `I` a `1`. |
| `invalid` | `invalid_check_digit` | Position 9 does not match the other characters, for a North American manufacturer. | Ask the user to check each character: it is usually a typo. |

Every answer is billed 1 credit, including invalid VINs. A VIN describes a vehicle, never its owner.

## How the check digit works

Position 9 is computed from the 16 other characters, as 49 CFR 565.15 specifies. Each letter gets a value (A = 1 to H = 8, J = 1 to N = 5, P = 7, R = 9, S = 2 to Z = 9), each position a weight (8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2), and the weighted sum is divided by 11. The remainder is the check digit, written `X` when it is 10.

U.S. rules make the check digit mandatory, and North American manufacturers apply it. Elsewhere, position 9 is not always a check digit. So `invalid_check_digit` is only reported when the first character is `1` to `5` (North America). For other VINs a mismatch shows in `check_digit.valid`, and `valid` stays `true`.

## How the model year is read

Position 10 is a code that repeats every 30 years:

| Code | Years | Code | Years |
|---|---|---|---|
| `A` | 1980, 2010 | `S` | 1995, 2025 |
| `B` | 1981, 2011 | `T` | 1996, 2026 |
| `C` | 1982, 2012 | `V` | 1997, 2027 |
| `D` | 1983, 2013 | `W` | 1998, 2028 |
| `E` | 1984, 2014 | `X` | 1999, 2029 |
| `F` to `H` | 1985 to 1987, 2015 to 2017 | `Y` | 2000, 2030 |
| `J` to `N` | 1988 to 1992, 2018 to 2022 | `1` to `9` | 2001 to 2009, 2031 to 2039 |
| `P`, `R` | 1993, 1994, 2023, 2024 | | |

For North American manufacturers, the API picks the cycle from position 7, the rule 49 CFR 565.15 sets for passenger cars, multipurpose passenger vehicles and trucks of 10,000 lb or less: a digit means 1980 to 2009, a letter 2010 to 2039. For other VINs the estimate is the most recent matching year. Outside North America position 10 is not always a year, so treat `model_year.estimate` as a hint there.

## Where the data comes from

The local decoding follows 49 CFR Part 565 and the ISO 3780 regions. Vehicle details come from [NHTSA vPIC](https://vpic.nhtsa.dot.gov/api/), a public U.S. Government service built from the data manufacturers file with NHTSA. vPIC covers vehicles made for the U.S. market: other VINs often decode partially or not at all, and `vehicle` is then `null`. See the [data sources page](https://qelka.com/data-sources).

## Examples

### Spot a letter VINs never use

This VIN has a letter `O` where a zero belongs. The API answers at once without calling vPIC, and the answer is billed because the check ran.

```bash title="cURL"
curl https://api.qelka.com/v1/vin \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"vin": "1HGCM82633A0O4352"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/vin', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ vin: '1HGCM82633A0O4352' }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/vin",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"vin": "1HGCM82633A0O4352"},
    timeout=30,
)
result = response.json()
print(result)
```

```json title="Response"
{
  "id": "lkp_01M8714DYDTVQ8XFRVNFDDR2TA",
  "object": "vin",
  "input": "1HGCM82633A0O4352",
  "valid": false,
  "status": "invalid",
  "reason": "invalid_characters",
  "vin": "1HGCM82633A0O4352",
  "wmi": null,
  "vds": null,
  "vis": null,
  "check_digit": null,
  "model_year": null,
  "plant_code": null,
  "serial_number": null,
  "vehicle": null,
  "nhtsa": null,
  "credits_used": 1,
  "cached": false
}
```

### Test without calling vPIC

Test keys decode the VIN on our servers and return a sample vehicle, make `TEST MAKE`, without calling vPIC. With a test key in `QELKA_API_KEY`, this request returns:

```bash title="cURL"
curl https://api.qelka.com/v1/vin \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"vin": "1HGCM82633A004352"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/vin', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ vin: '1HGCM82633A004352' }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/vin",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"vin": "1HGCM82633A004352"},
    timeout=30,
)
result = response.json()
print(result)
```

```json title="Response"
{
  "id": "lkp_01M8714EVPB58KPCJ0K935XXMY",
  "object": "vin",
  "input": "1HGCM82633A004352",
  "valid": true,
  "status": "valid",
  "reason": null,
  "vin": "1HGCM82633A004352",
  "wmi": { "code": "1HG", "region": "north_america", "small_manufacturer": false },
  "vds": "CM826",
  "vis": "3A004352",
  "check_digit": { "value": "3", "expected": "3", "valid": true, "required": true },
  "model_year": { "code": "3", "candidates": [2003], "estimate": 2003 },
  "plant_code": "A",
  "serial_number": "004352",
  "vehicle": {
    "make": "TEST MAKE",
    "model": "TEST MODEL",
    "model_year": null,
    "trim": null,
    "series": null,
    "body_class": null,
    "vehicle_type": "PASSENGER CAR",
    "doors": null,
    "drive_type": null,
    "fuel_type": null,
    "engine": { "cylinders": null, "displacement_l": null, "horsepower": null, "configuration": null, "model": null },
    "transmission": { "style": null, "speeds": null },
    "manufacturer": null,
    "plant": { "city": null, "state": null, "country": null, "company": null },
    "gvwr": null
  },
  "nhtsa": {
    "error_codes": ["0"],
    "message": "0 - Simulated decode of 1HGCM82633A004352 for a test key."
  },
  "credits_used": 0,
  "cached": false
}
```

## Errors

| Status | Type | When |
|---|---|---|
| 400 | [invalid_request](https://qelka.com/docs/errors#invalid_request) | `vin` is missing, empty or longer than 40 characters, the body is not a JSON object, or it has a field the request table does not list |
| 401 | [invalid_api_key](https://qelka.com/docs/errors#invalid_api_key) | The key is missing, unknown or revoked |
| 402 | [insufficient_credits](https://qelka.com/docs/errors#insufficient_credits) | Your balance is less than 1 credit (live keys only) |
| 403 | [forbidden](https://qelka.com/docs/errors#forbidden) | The key is restricted to other endpoints |
| 405 | [invalid_request](https://qelka.com/docs/errors#invalid_request) | The method is not `POST` |
| 429 | [rate_limited](https://qelka.com/docs/errors#rate_limited) | Too many requests: wait `Retry-After` seconds |
| 500 | [internal_error](https://qelka.com/docs/errors#internal_error) | Unexpected error on our side: retry with backoff |
| 502 | [upstream_unavailable](https://qelka.com/docs/errors#upstream_unavailable) | NHTSA vPIC could not be reached, answered with an error or did not answer in time: retry later |

No error is billed. A VIN that fails a check is not an error: it is a `200` with `valid: false`.

## Related

- [VIN decoder API](https://qelka.com/products/vin-decoding)
- Free tool: [VIN decoder](https://qelka.com/tools/vin-decoder)
- [Batch](https://qelka.com/docs/api-reference/batch): up to 100 VINs in one call, each item with `type: "vin"`
- [Bulk](https://qelka.com/docs/api-reference/bulk): a whole file of VINs with `type=vin`
- [Caching](https://qelka.com/docs/caching), [Errors](https://qelka.com/docs/errors), [Test mode](https://qelka.com/docs/test-mode)
