Sdks
Java SDK
A Java client for building with the Unii API.
Overview
The Unii Java SDK provides a type-safe client for the Unii API. It supports chat completions, streaming, knowledge bases, and more with a fluent, builder-style API.
Important
The SDK API surface shown on this page is illustrative. Verify the actual method signatures and types against the latest SDK documentation before using them in production.
Installation
Add the SDK as a dependency using Maven or Gradle:
<dependency>
<groupId>dev.unii</groupId>
<artifactId>unii-java</artifactId>
<version>1.0.0</version>
</dependency>Requires Java 17 or later.
Initialize the client
Create a client instance with your API key:
import dev.unii.UniiClient;
import dev.unii.UniiClientBuilder;
UniiClient client = UniiClientBuilder.create()
.apiKey(System.getenv("UNII_API_KEY"))
.build();The SDK reads UNII_API_KEY from the environment automatically if you don't set an explicit API key.
Create a chat completion
var response = client.chat().completions().create(
ChatRequest.builder()
.model("unii-latest")
.addMessage("system", "You are a helpful assistant.")
.addMessage("user", "Explain RAG in one sentence.")
.temperature(0.7)
.maxTokens(256)
.build()
);
System.out.println(response.choices().get(0).message().content());Streaming responses
var stream = client.chat().completions().createStream(
ChatRequest.builder()
.model("unii-latest")
.addMessage("user", "Explain RAG in detail.")
.stream(true)
.build()
);
stream.forEach(chunk -> {
String content = chunk.choices().get(0).delta().content();
if (content != null) {
System.out.print(content);
}
});Error handling
try {
var response = client.chat().completions().create(request);
} catch (UniiApiException e) {
System.err.printf("API error: %d - %s%n", e.statusCode(), e.message());
}Methods reference
Key client methods:
| Parameter | Type | Description |
|---|---|---|
chat().completions().create() | method | Create a chat completion. Returns a completion response object. |
chat().completions().createStream() | method | Create a streaming chat completion. Returns a stream of chunk objects. |
knowledgeBases().create() | method | Create a new knowledge base with a name and optional description. |
verifyAuth() | method | Verify that the current API key is valid and active. |
Next steps
- Follow the Quickstart to make your first API call.
- Read the API Reference for complete endpoint documentation.
- Compare with the TypeScript SDK or Python SDK.