Quick setup examples

Java (HTTP) Quickstart

Call the Unison brain from Java using the built-in java.net.http.HttpClient — no extra dependencies.

java.net.http.HttpClient (introduced in Java 11) handles both calls. No Maven or Gradle dependencies needed beyond the JDK.

Prerequisites

export UNISON_TOKEN=usk_live_...

Java 11 or later.

Recall — fetch prompt-ready context

import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import com.fasterxml.jackson.databind.ObjectMapper; // or any JSON lib

public class UnisonRecall {
    private static final String BASE  = "https://brain.unisonlabs.ai";
    private static final String TOKEN = System.getenv("UNISON_TOKEN");

    public static String recall(String query) throws Exception {
        String q = URLEncoder.encode(query, StandardCharsets.UTF_8);
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(BASE + "/v1/brain/context?q=" + q + "&k=5&mode=auto"))
            .header("Authorization", "Bearer " + TOKEN)
            .GET()
            .build();

        HttpClient client = HttpClient.newHttpClient();
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        // Parse with your preferred JSON library; example uses Jackson
        ObjectMapper mapper = new ObjectMapper();
        var node = mapper.readTree(response.body());

        if (node.get("weakEvidence").asBoolean()) return "";
        return node.get("contextMd").asText();
    }

    public static void main(String[] args) throws Exception {
        System.out.println(recall("payment service architecture"));
    }
}

If you prefer to avoid Jackson, swap the JSON parsing block for any library (Gson, org.json, etc.) — the HTTP layer stays identical.

Persist — write memory to the brain

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class UnisonPersist {
    private static final String BASE  = "https://brain.unisonlabs.ai";
    private static final String TOKEN = System.getenv("UNISON_TOKEN");

    public static void persist() throws Exception {
        String body = """
            {
              "items": [
                {
                  "type": "conversation",
                  "turns": [
                    { "role": "user",      "content": "What queue library should we use?" },
                    { "role": "assistant", "content": "Switched to pgmq — simpler ops than Redis." }
                  ],
                  "sourceRef": "session-1",
                  "visibility": "private"
                }
              ]
            }
            """;

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(BASE + "/v1/brain/ingest"))
            .header("Authorization",  "Bearer " + TOKEN)
            .header("Content-Type",   "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build();

        HttpClient client = HttpClient.newHttpClient();
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }

    public static void main(String[] args) throws Exception {
        persist();
    }
}

On this page