From 3d3b996839e701ae226b5ed9299e31f79c73c111 Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Wed, 20 May 2026 22:57:43 +0200 Subject: [PATCH] Refine Ollama response content-type validation Allow application/json and missing content-type headers, only rejecting obvious non-JSON responses like HTML error pages. This improves compatibility with different Ollama server configurations. --- src/ollama-client.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ollama-client.ts b/src/ollama-client.ts index 4523b46..6bd58a5 100644 --- a/src/ollama-client.ts +++ b/src/ollama-client.ts @@ -163,8 +163,10 @@ export class OllamaClient { } const contentType = response.headers?.get?.('content-type'); - if (contentType && !contentType.includes('application/x-ndjson')) { - throw new Error('Invalid response format'); + // Ollama may return application/x-ndjson, application/json, or no content-type at all. + // Reject only obvious non-JSON responses (e.g., HTML error pages). + if (contentType && contentType.includes('text/html')) { + throw new Error('Invalid response format: server returned HTML instead of JSON'); } reader = response.body.getReader();