Integration guide

How to use Spring Boot with an OpenAI-compatible endpoint (Java)

Spring Boot integration guide for Java. Connect to an OpenAI-compatible endpoint with a base URL swap and keep the same request schema.

Updated 2026-01-06

Spring Boot works with OpenAI-compatible APIs by switching the base URL and API key.

This guide shows a Java example plus a test vector you can run to validate responses.

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

public class Main {
  public static void main(String[] args) throws Exception {
    String payload = """
{
  "model": "abliterated-model",
  "messages": [
    { "role": "user", "content": "Respond with: Spring Boot Java ready." }
  ],
  "temperature": 0.2
}
""";

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.abliteration.ai/v1/chat/completions"))
        .header("Authorization", "Bearer " + System.getenv("ABLIT_KEY"))
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString(payload))
        .build();

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

    System.out.println(response.body());
  }
}

Configure Spring Boot

Follow this checklist to point your integration at the OpenAI-compatible endpoint.

OpenAI-compatible payload

Use this request body as a known-good payload before customizing parameters.

{
  "model": "abliterated-model",
  "messages": [
    { "role": "user", "content": "Respond with: Spring Boot Java ready." }
  ],
  "temperature": 0.2
}

Streaming and tool calling readiness

If you stream responses or send tool definitions, keep the OpenAI-compatible schema and validate against the OpenAPI spec.