Skip to content

LLM service contract

llm-service serves the shop's Ollama API: chat, generate and tool-calling chat (/api/v1/ollama/*). It used to live in the backend; it was split out with no visible change, strangler style: the gateway routes the four Ollama paths to llm-service, and the backend keeps answering everything else.

Runtime

Item Value
Repository slawekradzyminski/llm-service-rs, default branch master
Image slawekradzyminski/llm-service-rs (Rust, distroless), 62 MB image, a few MiB of memory in a 64 MiB container
Port 4007 (internal only, behind the gateway)
Database None. Users, system prompts, products and the traffic log stay in the backend
Authentication The bearer token is checked by the backend (POST /internal/v1/llm/introspect), so revocation and the deleted-user 500 stay exactly as before
Environment BACKEND_BASE_URL, LLM_SERVICE_TOKEN (required), and the backend's own settings with the backend's profile defaults (SPRING_PROFILES_ACTIVE, OLLAMA_BASE_URL, OLLAMA_MAX_TOOL_CALL_ITERATIONS, SECURITY_RATE_LIMIT_ENABLED, SECURITY_RATE_LIMIT_TRUST_FORWARDED_HEADERS, SECURITY_RATE_LIMIT_OLLAMA_*, SERVER_FORWARD_HEADERS_STRATEGY, APP_CORS_ALLOWED_ORIGIN_PATTERNS, LOGGING_*, TRACING_*)
Requires backend-rs with the LLM internal API (LLM_SERVICE_TOKEN set on the backend)
Health GET /actuator/health; the image has no shell, so Compose runs ["CMD", "/llm-service-rs", "healthcheck"]

Every Compose file gives llm-service the same values as its backend for the settings both read, so the two answer the same way.

Public API (unchanged)

Gateway location Example
= /api/v1/ollama/generate POST, SSE stream
= /api/v1/ollama/chat POST, SSE stream with the user's chat system prompt first
= /api/v1/ollama/chat/tools POST, SSE stream of the tool loop
= /api/v1/ollama/chat/tools/definitions GET

They are exact locations with the backend /api/v1/ location's proxy settings. Any other /api/v1/ollama/... path still reaches the backend and answers as before (401 or 404). The rate limits (ollama-user and ollama-ip) are counted by llm-service; nothing else shared them.

Backend internal API

llm-service calls the backend with X-Service-Token: ${LLM_SERVICE_TOKEN}. The backend accepts that token only on these paths; a blank token disables them (404). /internal/ is 404 at every gateway.

Call Purpose
POST /internal/v1/llm/introspect What the backend's JWT filter decides for a bearer token: user and roles, invalid (401), internal (500) or unavailable (503)
GET /internal/v1/llm/prompts?username= The effective chat and tool system prompts
GET /internal/v1/llm/products/{id}, ?name= get_product_snapshot: the product as the backend's ProductDto
GET /internal/v1/llm/product-summaries list_products: ids, names and the total
POST /internal/v1/traffic/records The traffic record of each exchange llm-service answered. It is sent before the response leaves, and the backend stores and publishes it as if it had captured it

If the backend cannot be reached while authenticating, llm-service answers 503 Database unavailable, as the backend did when its database was down.

Deployment in this repository

  • Compose. llm-service in lightweight-docker-compose.yml and docker-compose.yml (64 MiB); llm-service and aitesters-llm-service in docker-compose.server.yml. They start after a healthy backend. docker-compose.model-mock.yml points it at the ollama mock.
  • Course stack. docker-compose.compatibility.yml puts a small nginx router (nginx/conf.d/compatibility-router.conf) on 14001 and 14002. It sends the four Ollama paths to llm-service and admin-llm-service and everything else to the backends, passing requests through unchanged. COMPAT_LLM_IMAGE selects a candidate image.
  • Secrets. Ansible adds LLM_SERVICE_TOKEN to .env.runtime and .env.aitesters, and renders .env.llm and .env.aitesters-llm from Vault (llm_service_token, aitesters_llm_service_token). Both are at least 32 characters and distinct from every other token.
  • Image pin. Every profile pins slawekradzyminski/llm-service-rs:1.0.0@sha256:… (see the current compatibility set). The first release went out with a PENDING_LLM_SERVICE_DIGEST placeholder, which scripts/verify-release-images.py, scripts/verify-image-pins.py and the Ansible image gate refused until scripts/release-train.py pin wrote the published digest. llm-service is part of the release train.

Rollout

Steps 1 to 3 are done: backend-rs 1.1.0 and llm-service-rs 1.0.0 run in every profile and in production since 1 December 2026. Step 4 is open.

  1. Release backend-rs with the internal API, and set LLM_SERVICE_TOKEN on the backends. This is additive: the backend still serves the Ollama API.
  2. Publish llm-service-rs 1.0.0 and pin its digest.
  3. Deploy: the gateways route the four paths to llm-service. To roll back, revert the gateway locations; the backend's handlers are still there.
  4. Later: remove the Ollama handlers from the backend once no profile needs them.