llama.cpp server

swaleio/llamacpp-server

Category: Machine learning & AI Latest version b12855 · 2026-12-01 View versions

llama.cpp server

Starts llama-server from llama.cpp for a GGUF model. It answers OpenAI-compatible requests (/v1/chat/completions, /v1/completions, /v1/embeddings, /v1/models), llama.cpp's own /completion and /tokenize, and GET /health, which returns 200 once the model is loaded.

The image is llama.cpp's CUDA 13 build, used as-is: its entrypoint is llama.cpp's /app/tools.sh dispatcher, and the leading --server argument runs llama-server with the rest. llama-server listens only on 127.0.0.1 unless told otherwise, so the definition always passes --host 0.0.0.0, which makes it reachable by the run's other tasks.

This is a runner task: it serves requests indefinitely and never exits on its own. Its lifetime is bounded by its own terminate_on list — the platform terminates the runner when the tasks listed there complete. A workflow that starts this task without wiring terminate_on never finishes.

Inputs

Input Required Default Description
model yes — Absolute path of the .gguf model file, such as one swaleio/hf-download or swaleio/llamacpp-quantize placed on the workspace.
port no 9931 Port the server listens on, llama-server's own default in this build. Consumers combine it with the runner's ip-address, so every consumer URL must use the same port.
ctx_size no 0 Context size in tokens; 0, llama-server's default, takes the model's training context. A smaller value saves memory on long-context models.

Outputs

None. Runner tasks are long-lived pods terminated via terminate_on and get no output-tracking sidecar, so this task declares no outputs. Consumers read the server's responses over HTTP instead.

Compute

GPU recommended. The image loads its CUDA backend and offloads as many layers as fit when the compute type has a GPU, and falls back to its CPU backend otherwise. A quantized model of a few billion parameters answers at a usable speed on a CPU compute type; larger models want a GPU.

Runner lifecycle and consumers

  • Termination: the runner's own terminate_on lists its consumers. When every task in that list completes, the platform terminates the runner.
  • Address: consumers reach the server at ${{tasks.<id>.ip-address}} on the server's port — 9931 unless the step passed port.
  • Ordering: every consumer MUST list the runner in its own start_on — the address only exists once the runner task has started.
  • Readiness: the address is available at pod start, before the model is loaded. Poll GET /health until it returns 200, with swaleio/http-request and retry: "360", retry_delay: "5": a check every 5 seconds for up to 30 minutes.

Example

Fetch a 4-bit GGUF model, serve it, wait for it to load, and ask one question:

name: llama.cpp server example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      model:
        name: Fetch model
        uses: swaleio/hf-download
        args:
          repo: Qwen/Qwen2.5-0.5B-Instruct-GGUF
          include: "qwen2.5-0.5b-instruct-q4_k_m.gguf"
          dest: ${{env.WORKFLOW_STORAGE}}/gguf

      serve:
        name: Serve model
        uses: swaleio/llamacpp-server
        start_on: [model]
        terminate_on: [ask]
        args:
          model: ${{env.WORKFLOW_STORAGE}}/gguf/qwen2.5-0.5b-instruct-q4_k_m.gguf

      wait_ready:
        name: Wait for server
        uses: swaleio/http-request
        start_on: [serve]
        args:
          url: http://${{tasks.serve.ip-address}}:9931/health
          retry: "360"
          retry_delay: "5"
          expected_status: "200"

      ask:
        name: Chat completion
        uses: swaleio/http-request
        start_on: [wait_ready]
        args:
          url: http://${{tasks.serve.ip-address}}:9931/v1/chat/completions
          method: POST
          headers: |
            Content-Type: application/json
          body: '{"messages":[{"role":"user","content":"Say hello in one sentence."}],"max_tokens":64}'
          expected_status: "200"
          response_path: ${{env.WORKFLOW_STORAGE}}/completion.json

The model is Apache-2.0. Later tasks read the answer at ${{env.WORKFLOW_STORAGE}}/completion.json.


For the workflow syntax these examples use, see the workflow definition reference in the Swale documentation.

Licensed under the MIT License.