Why you'd build this proxy
Most cloud-shaped chat UIs and SDKs (OpenAI Python SDK, Vercel AI SDK, LangChain streaming hooks) consume SSE. If you want to drop Ollama into one of those without rewriting the frontend, build a tiny proxy that converts NDJSON → SSE on the way out.
The shape of the conversion
- Ollama emits
{json}\n; SSE wantsdata: {json}\n\n. - OpenAI-compatible SSE clients expect a
data: [DONE]\n\nsentinel at the end. - The chunk shape inside
data:usually has to be reformatted into OpenAI's delta shape:{"choices": [{"delta": {"content": "..."}}]}.
Don't reinvent OpenAI compatibility
Ollama already exposes /v1/chat/completions as an OpenAI-compatible endpoint. If all you need is "drop-in OpenAI SDK", point the SDK at http://localhost:11434/v1 and skip the proxy. Build your own proxy only when you need transformations Ollama's compat endpoint doesn't do (custom auth, observability, request shaping).