Class OllamaCodec

  • All Implemented Interfaces:
    ProviderCodec

    public class OllamaCodec
    extends Object
    implements ProviderCodec
    Codec for Ollama /api/chat endpoint (version ollama-2025).

    Ollama uses a distinct JSON shape with a top-level message object (not an array of choices). Token counts are exposed as prompt_eval_count and eval_count.

    Streaming limitation: Ollama's native wire format is NDJSON (newline-delimited JSON), not SSE. This codec represents each chunk as an SseEvent with the JSON line as the data field. When MockServer sends them, the SSE handler emits data: <json>\n\n which is close enough for most SDK clients to parse. Strict NDJSON support is out of scope.

    Tool calls use Ollama 0.3+ format where arguments is a JSON object (not a JSON-as-string like OpenAI).