---
title: "Java"
description: "Official CarsXE SDK for Java."
canonical_url: "https://docs.carsxe.com/docs/sdks/java"
markdown_url: "https://docs.carsxe.com/docs/sdks/java.md"
last_updated: "1980-01-01"
x_farming_labs_generated_preamble: true
agent:
  task: "Install and call the CarsXE Java SDK for vehicle-data endpoints."
  outcome: "The Java client is installed and its documented example returns a successful CarsXE response."
  prerequisites:
    - "A valid CarsXE API key."
    - "The runtime and package tooling required by the Java installation steps."
  verification:
    - "Run the documented Java example and confirm it authenticates and returns vehicle data without an SDK or API error."
  failureModes:
    - symptom: "The Java client cannot install, authenticate, or complete the example request."
      resolution: "Verify the runtime version, package installation, API-key environment variable, and endpoint inputs before rerunning the example."
---

# Java
URL: /docs/sdks/java
LLM index: /llms.txt
Description: Official CarsXE SDK for Java.
Related: /docs/sdks, /docs/get-started

<!-- farming-labs:agent-contract:start -->
## Agent Contract

Task: Install and call the CarsXE Java SDK for vehicle-data endpoints.
Outcome: The Java client is installed and its documented example returns a successful CarsXE response.

### Prerequisites

- A valid CarsXE API key.
- The runtime and package tooling required by the Java installation steps.

### Verification

- Run the documented Java example and confirm it authenticates and returns vehicle data without an SDK or API error.

### Failure Modes

- The Java client cannot install, authenticate, or complete the example request. — Recovery: Verify the runtime version, package installation, API-key environment variable, and endpoint inputs before rerunning the example.
<!-- farming-labs:agent-contract:end -->

Task: Install and call the CarsXE Java SDK for vehicle-data endpoints.
Related: /docs/sdks/java, /docs/get-started, /docs/sdks

The `carsxe` artifact is the official CarsXE client for Java. It wraps the REST API with typed methods and handles authentication. Requires Java 11 or later.

## Installation

<CodeGroup title="Add the dependency">

```xml {{ title: "Maven" }}
<dependency>
  <groupId>io.github.carsxe</groupId>
  <artifactId>carsxe</artifactId>
  <version>LATEST</version>
</dependency>
```

```groovy {{ title: "Gradle" }}
implementation 'io.github.carsxe:carsxe:LATEST'
```

</CodeGroup>

## Quick start

```java
import io.github.carsxe.CarsXE;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        CarsXE carsxe = new CarsXE(System.getenv("CARSXE_API_KEY"));
        Map<String, String> params = new HashMap<>();
        params.put("vin", "WBAFR7C57CC811956");

        try {
            Map<String, Object> vehicle = carsxe.specs(params);
            System.out.println(vehicle);
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}
```

## Methods

### Core

| Method | Description |
|---|---|
| `specs(params)` | Decode a 17-character VIN into full vehicle specifications |
| `marketvalue(params)` | Retail, trade-in, and auction value estimates |
| `recalls(params)` | Open safety recalls by VIN, make, model, or year |
| `platedecoder(params)` | VIN lookup from a license plate (50+ countries) |
| `history(params)` | Title events, salvage, junk, and insurance records |

### Bulk recall batch

| Method | Description |
|---|---|
| `submitBulkRecallBatch(params)` | Submit a batch of VINs for recall lookup |
| `getBulkRecallBatchStatus(batchId)` | Poll job status |
| `getBulkRecallBatchResults(batchId)` | Retrieve completed results |
| `getBulkRecallBatchDownloadUrl(batchId)` | Get a CSV download URL |

## Endpoint examples

Runnable examples for each method. All of them assume the `carsxe` instance from [Quick start](#quick-start) and a fresh `Map<String, String> params = new HashMap<>()`.

### International VIN Decoder

```java
params.put("vin", "WF0MXXGBWM8R43240");
Map<String, Object> internationalVin = carsxe.internationalVinDecoder(params);
System.out.println(internationalVin);
```

### Market Value

```java
params.put("vin", "WBAFR7C57CC811956");
Map<String, Object> marketValue = carsxe.marketvalue(params);
System.out.println(marketValue);
```

### Vehicle History

```java
params.put("vin", "WBAFR7C57CC811956");
Map<String, Object> history = carsxe.history(params);
System.out.println(history);
```

### License Plate Decoder

```java
params.put("plate", "7XER187");
params.put("state", "CA");
params.put("country", "US");
Map<String, Object> plateInfo = carsxe.platedecoder(params);
System.out.println(plateInfo);
```

### Vehicle Images

```java
params.put("make", "BMW");
params.put("model", "X5");
params.put("year", "2019");
Map<String, Object> images = carsxe.images(params);
System.out.println(images);
```

### Vehicle Recalls

```java
params.put("vin", "1C4JJXR64PW696340");
Map<String, Object> recalls = carsxe.recalls(params);
System.out.println(recalls);
```

### Plate Image Recognition

Takes the image URL directly rather than a params map.

```java
String imageUrl = "https://imagedelivery.net/moyiiSImjJPI_EZVxNMBBw/f49aed53-d736-4370-f3f4-97418841c800/public";
Map<String, Object> plateRecognition = carsxe.plateImageRecognition(imageUrl);
System.out.println(plateRecognition);
```

### VIN OCR from Image

```java
String imageUrl = "https://imagedelivery.net/moyiiSImjJPI_EZVxNMBBw/base/images/vin-ocr/vin/public";
Map<String, Object> vinOcr = carsxe.vinOcr(imageUrl);
System.out.println(vinOcr);
```

### Year-Make-Model Search

```java
params.put("year", "2023");
params.put("make", "Toyota");
params.put("model", "Camry");
Map<String, Object> ymm = carsxe.yearMakeModel(params);
System.out.println(ymm);
```

### OBD Code Decoder

```java
params.put("code", "P0115");
Map<String, Object> obdCodes = carsxe.obdcodesdecoder(params);
System.out.println(obdCodes);
```

### Lien and Theft

```java
params.put("vin", "2C3CDXFG1FH762860");
Map<String, Object> lienTheft = carsxe.LienAndTheft(params);
System.out.println(lienTheft);
```

## Error handling

Methods throw `Exception` on API errors. Wrap calls in a `try/catch` block:

```java
try {
    Map<String, Object> vehicle = carsxe.specs(params);
    System.out.println(vehicle);
} catch (Exception e) {
    System.err.println("Error: " + e.getMessage());
}
```

## Best practices

**Validate the environment variable at startup.**

```java
String apiKey = System.getenv("CARSXE_API_KEY");
if (apiKey == null || apiKey.isBlank()) {
    throw new IllegalStateException("CARSXE_API_KEY is not set");
}
CarsXE carsxe = new CarsXE(apiKey);
```

**Create one instance and reuse it.** The client manages connection pooling internally — don't instantiate per request.

**Store your key in an environment variable.** Never hardcode it or commit it to source control.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
