AI Infrastructure · Self-hosted LLM

Local AI Gateway

One 27B vision-language model on a Mac Studio, shared fairly by every app on the machine through an Ollama-compatible API.

Type
AI infrastructure
Year
2026
Platforms
Web
Status
Private system
Local AI Gateway — AI Infrastructure · Self-hosted LLM

(01)Overview

A gateway that replaced Ollama on this machine without any app noticing: the same API on the same port, plus OpenAI-compatible endpoints. Behind it, a 4-bit Qwen3.8 27B model on Apple’s MLX serves text and images from one server, and every client gets a fair share of the queue.

(02)The Problem

Several AI products on one machine — OstamAI, FinMetre, MotoTracker and others — all wanted the same large model. One busy app could starve the others, a hung model blocked everyone, and apps that needed strict JSON or images each solved it differently.

(03)The Solution

A single gateway in front of the model: apps keep calling the address they always used, are told apart by a header or by port, and share the model through a weighted fair queue. JSON schemas are enforced centrally and a watchdog restarts the model if it stops answering.

(04)What We Built

  1. 01

    Ollama API and OpenAI /v1 on the same port — no app had to change

  2. 02

    Weighted fair queue per client; abandoned requests give their slot back

  3. 03

    Text, images and decisions served by one MLX vision-language server

  4. 04

    JSON and JSON-schema output validated, with one corrective retry

  5. 05

    A /decide endpoint that answers yes/no, choice and score questions from next-token probabilities

  6. 06

    Watchdog probes and restarts the model after a stall; upstream timeouts free stuck slots

(05)Highlights

  • 01

    Drop-in Ollama + OpenAI API

  • 02

    Fair queue per app with weights

  • 03

    Self-healing watchdog

(06)Outcome

  • Every AI product on the machine shares one 27B model without starving each other
  • Five typed decisions come back in roughly 5–7 seconds through /decide
  • Rollback to plain Ollama is a documented three-command switch

Our role

  • Infrastructure
  • AI Systems

Tech stack

  • FastAPI
  • MLX / mlx_vlm
  • Qwen3.8 27B (4-bit)
  • llama.cpp embeddings
  • launchd

Something like this?

Want something like this? Every project can include design, development, deployment and ongoing improvements.