# Java

URL: https://docs.hanzo.ai/docs/sdks/java

> ai.hanzo:hanzo-java-cloud on Maven Central — the generated client for every /v1 capability, on OkHttp and Gson.

The Java client is generated from the API's own document onto OkHttp and Gson —
the same HTTP and JSON stack the [Kotlin](https://docs.hanzo.ai/docs/sdks/kotlin) client uses, so a
JVM project that pulls both pulls one stack.

## Install

`ai.hanzo:hanzo-java-cloud` is on Maven Central. Java 11 or newer.

```kotlin
// build.gradle.kts
repositories { mavenCentral() }
dependencies { implementation("ai.hanzo:hanzo-java-cloud:8.5.156") }
```

```xml
<dependency>
  <groupId>ai.hanzo</groupId>
  <artifactId>hanzo-java-cloud</artifactId>
  <version>8.5.156</version>
</dependency>
```

## The shape

One `ApiClient`, one class per capability:

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.AiApi;
import ai.hanzo.cloud.model.AiModelList;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

AiModelList models = new AiApi(client).getModels();
```

`setBearerToken` also takes a `Supplier<String>`, which is what you want when
the credential is an IAM access token that refreshes rather than a static
`sk-`. See [Authentication](https://docs.hanzo.ai/docs/api-keys).

The class is the capability and the method is the operation, both derived from
the document — the [reference](https://docs.hanzo.ai/docs/openapi) prints the pair per operation.
Every call throws `ApiException`, which carries the status code and the response
body.

## Resources

- Source — [hanzoai/java-sdk](https://github.com/hanzoai/java-sdk)
- [Every `/v1` operation →](https://docs.hanzo.ai/docs/openapi)
