Open Model Chat Backend is a TypeScript + Express service that wraps local Ollama models and exposes JSON + streaming endpoints for chat and vision use cases. A frontend application Open Model Frontend was developed to utilise this application's capabilities.
- Chat with a local Ollama model.
- Stream chat responses via Server-Sent Events (SSE).
- Vision endpoint that accepts an uploaded image and streams the response.
- List available local Ollama models with additional details.
- Node.js + TypeScript
- Express + CORS
- Multer (file uploads)
- Ollama JS client
- Node.js 18+ (or newer)
- npm
- Ollama installed and running locally
- Install dependencies:
npm install
- Start the dev server:
npm run dev
- Build and run in production mode:
npm run build npm start
The server listens on PORT (default 3000).
-
Install Ollama for your OS:
- macOS: install the Ollama app.
- Linux: use the official install script.
- Windows: use the Ollama installer.
-
Start the Ollama service.
-
Pull the default model used by this backend:
ollama pull gemma3:4b
-
Verify Ollama is running:
ollama list
If you want to use a different model, pass model in the request body to the chat/stream/vision endpoints.
You can install any Ollama model you want locally and switch models per request by sending the model field in the payload. The backend simply forwards the model name to Ollama, so whatever you have pulled locally can be used.
Install a model:
ollama pull llama3.1:8bUse that model in a request:
{
"model": "llama3.1:8b",
"messages": [
{ "role": "user", "content": "Explain the architecture." }
]
}Notes:
- If
modelis omitted, the server defaults togemma3:4b. - Use
ollama listto see which models are available locally.
Base path: /api/ai
All JSON responses use this shape:
{
"status": true,
"message": "Response from AI model",
"data": "..."
}On error:
{
"status": false,
"message": "Error message",
"error": "..."
}Send a single prompt and receive a full response.
Request body:
{
"message": "Say hello"
}Example:
curl -X POST http://localhost:3000/api/ai/chat \
-H "Content-Type: application/json" \
-d '{"message":"Say hello"}'Stream tokens using SSE. You can specify a model and pass a full messages array.
Request body:
{
"model": "gemma3:4b",
"messages": [
{ "role": "user", "content": "Summarize this project." }
]
}Example:
curl -N -X POST http://localhost:3000/api/ai/stream \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Summarize this project."}]}'The server streams SSE events as:
data: {"token":"..."}
data: [DONE]
Upload an image and stream a response (SSE).
Form fields:
image(file, required)prompt(string, optional)model(string, optional)
Example:
curl -N -X POST http://localhost:3000/api/ai/vision \
-F "image=@/path/to/image.jpg" \
-F "prompt=Describe the image."Returns local Ollama models along with capability info.
Example:
curl http://localhost:3000/api/ai/getAvailableModelsWithDetails- Uploaded files are stored in
uploads/.