httpPostStreaming

fun httpPostStreaming(endpoint: String, jsonBody: String, onLine: (String) -> Unit, shouldStop: () -> Boolean = { false }, timeoutMs: Int, port: Int = defaultPort())

Sends a POST request to the LLAMA-Server and streams the response as SSE lines.

SSE framing contract

The llama.cpp server emits a minimal SSE stream:

  • Each chunk is a data: {json} line followed by a blank line.

  • The stream ends with data: [DONE].

  • No event:, id:, or retry: fields are sent under normal operation.

If the server ever emits those fields (e.g. after a llama.cpp upgrade), they are logged at INFO level so the change is visible in diagnostics.

Parameters

endpoint

The API endpoint path.

jsonBody

The JSON request body (should include "stream": true).

onLine

Callback invoked for each SSE data: line as it arrives.

shouldStop

Callback that returns true to abort streaming early.

timeoutMs

Read timeout in milliseconds.

port

Optional port override. Defaults to the current server port.

Throws

if the server returns a non-2xx status code.