diff --git a/src/main/java/ee/carlrobert/llm/client/ollama/OllamaClient.java b/src/main/java/ee/carlrobert/llm/client/ollama/OllamaClient.java index 3918570..18adde8 100644 --- a/src/main/java/ee/carlrobert/llm/client/ollama/OllamaClient.java +++ b/src/main/java/ee/carlrobert/llm/client/ollama/OllamaClient.java @@ -244,10 +244,15 @@ private void processStreamRequest( private HttpRequest buildPostHttpRequest( Object request, String path) throws JsonProcessingException { - return HttpRequest.newBuilder(URI.create(BASE_URL + path)) + var requestBuilder = HttpRequest.newBuilder(URI.create(BASE_URL + path)) .POST(HttpRequest.BodyPublishers.ofString(new ObjectMapper().writeValueAsString(request))) - .header("Content-Type", "application/json") - .timeout(Duration.ofSeconds(30)) + .header("Content-Type", "application/x-ndjson"); + + if (apiKey != null) { + requestBuilder.header("Authorization", "Bearer " + apiKey); + } + + return requestBuilder.timeout(Duration.ofSeconds(30)) .build(); }