> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Ollama (local models)

> Client-mode REST API connector for local Ollama generate, chat, embed, and tags — MQTT into edge LLMs with no cloud and no API key by default

Technical Preview

## Overview

A client-mode connector for a **curated** slice of the [Ollama API](https://docs.ollama.com/api) focused on IIoT / edge alarm text into **local** LLMs (no cloud):

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| POST generate | `POST /api/generate` | Edge classification / structured JSON; set `"stream": false` |
| POST chat | `POST /api/chat` | Chat with messages; `"stream": false` for MQTT one-shot |
| POST embed | `POST /api/embed` | Embeddings (supersedes legacy `/api/embeddings`) |
| GET tags | `GET /api/tags` | Health + local model list |
| (supporting) GET models | `GET /v1/models` | OpenAI-compatible model list |
| (supporting) POST chat/completions | `POST /v1/chat/completions` | OpenAI-compatible chat |

Default `BASE_ADDRESS` is `http://127.0.0.1:11434` with `USE_SSL "false"` (no trailing slash). For an HTTPS reverse proxy, set `USE_SSL "true"` and point `BASE_ADDRESS` at `https://your-host`. Topics use `ai/ollama/<object>/<verb>`. `REQUEST_TIMEOUT` is `120` for cold model load + inference.

See the base guide: [REST API Connectors](/latest/lot-language/routes/rest-api-routes).

> [!NOTE]
>
> **Auth:** none required for local Ollama. A reverse proxy may require `Authorization: Bearer &lt;token&gt;` — add that header and map Hub secrets into MQTT `api_token` if needed.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — Ollama (local models)
# Auth: none by default; reverse proxy may add Bearer
# BASE_ADDRESS: http://127.0.0.1:11434 (USE_SSL false)

DEFINE ROUTE OllamaRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "http://127.0.0.1:11434"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "false"
        WITH REQUEST_TIMEOUT '120'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT PostGenerate
        WITH SOURCE_TOPIC "ai/ollama/generate/post"
        WITH DESTINATION_TOPIC "ai/ollama/generate/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/generate"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
        WITH BODY "{payload}"
    ADD EVENT PostChat
        WITH SOURCE_TOPIC "ai/ollama/chat/post"
        WITH DESTINATION_TOPIC "ai/ollama/chat/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/chat"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
        WITH BODY "{payload}"
    ADD EVENT PostEmbed
        WITH SOURCE_TOPIC "ai/ollama/embed/post"
        WITH DESTINATION_TOPIC "ai/ollama/embed/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/embed"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
        WITH BODY "{payload}"
    ADD EVENT GetTags
        WITH SOURCE_TOPIC "ai/ollama/tags/list"
        WITH DESTINATION_TOPIC "ai/ollama/tags/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/tags"
        WITH HEADERS
            ADD "Accept" "application/json"
```

Full deployable file: `OllamaRestApi.lot` in the factory package (no `ADD METADATA`).

## Topics

| Event | Source topic | Destination topic |
| - | - | - |
| PostGenerate | `ai/ollama/generate/post` | `…/response` |
| PostChat | `ai/ollama/chat/post` | `…/response` |
| PostEmbed | `ai/ollama/embed/post` | `…/response` |
| GetTags | `ai/ollama/tags/list` | `…/response` |
| GetModels | `ai/ollama/models/list` | `…/response` |
| PostChatCompletions | `ai/ollama/chat/completions/post` | `…/response` |

## Configuration

1. Run Ollama locally (e.g. `docker run -d -p 11434:11434 ollama/ollama`) and pull a model (`ollama pull tinyllama`).
2. Set `BASE_ADDRESS` to `http://127.0.0.1:11434` (or your LAN/Docker host). Keep `USE_SSL "false"` for plain HTTP; use HTTPS + `USE_SSL "true"` behind a reverse proxy.
3. For edge alarm classification: publish to `ai/ollama/generate/post` with `"stream": false` and optional `"format": "json"` / JSON schema.
4. For chat-style prompts: publish to `ai/ollama/chat/post` with a `messages` array and `"stream": false`.
5. Use `GetTags` as a cheap health / model-list smoke before production workloads.
6. Optional OpenAI-shaped clients can use `GetModels` / `PostChatCompletions` under `/v1/...`.

## References

* [Ollama API](https://docs.ollama.com/api)
* [API reference (GitHub)](https://github.com/ollama/ollama/blob/main/docs/api.md)
* [OpenAI compatibility](https://docs.ollama.com/api/openai-compatibility)
* [Model library](https://ollama.com/library)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.