Python SDK, HTTP API & Automation

Every capability in the Desktop App and CLI is also available as a clean Python SDK, a typed FastAPI + SSE HTTP server, and structured CLI JSON output for CI pipelines and coding agents.


1. Python SDK (actuator.train, actuator.run, ...)

Install the actuator-train distribution (with [cuda] or [mlx]) and import actuator directly. The Python SDK invokes the exact same recipe builder and single-process training + Verdict pipeline as the CLI:

import actuator

# Train directly from local data or a Hugging Face dataset
run = actuator.train(
    data="my-data.jsonl",
    model="Qwen/Qwen3-4B",
    preset="balanced",        # "fast" | "balanced" | "best" | "low-memory"
    eval_mode="fast",         # "fast" | "strict" | "judge:<model>" | "none"
    engine="actuator",        # "actuator" | "unsloth" | "trl" | "mlx"
    preserve_kl=0.05,         # optional ML-native KL preservation anchor
    out="runs/support-bot",
    overwrite=True,
)

# Read the structured Before/After Verdict
print(run.verdict.status)     # "improved" | "inconclusive" | "regressed"
print(run.verdict.summary)
print(run.verdict.samples)    # side-by-side before/after greedy replies

# Chat programmatically
reply = run.chat("What is your return policy?")
print(reply)

# Export to auto-judged GGUF + Ollama
export = run.export(
    gguf="q4_k_m",
    imatrix=True,
    ollama="support-bot",
    out="runs/support-bot-gguf",
)
print(export.files)

Running a YAML Recipe or Transform from Python

import actuator

# Run any catalog or custom YAML recipe
run = actuator.run("recipes/catalog/sft/qwen3-4b-qlora.yaml")

# Evaluate any checkpoint against its base model
verdict = actuator.eval(
    model="runs/support-bot/export-native",
    against="Qwen/Qwen3-4B",
    data="heldout.jsonl",
)

# Merge or remove refusals with automatic Verdict
merged = actuator.merge("recipes/catalog/transform/merge-slerp-qwen3-8b.yaml", out="runs/merged")
ablit = actuator.abliterate("Qwen/Qwen3-8B", out="runs/abliterated")

2. Local FastAPI + SSE Server (actuator serve)

Drive Actuator from any language (TypeScript, Go, Rust, Python, curl) over its local HTTP API:

actuator serve --host 127.0.0.1 --port 8765

Key endpoints (full OpenAPI specification in docs/api/job-api-v0.yaml):

  • POST /v0/train/preview — Instant (<50 ms) in-process recipe & memory-fit preview
  • POST /v0/uploads — Binary multipart/form-data file upload (JSONL, CSV, Parquet, PDF, DOCX)
  • POST /v0/jobs — Start an isolated GPU training, export, or strict-eval job
  • GET /v0/events & GET /v0/jobs/{id}/stream — Real-time SSE stream of metrics, logs, and status
  • GET /v0/jobs/{id}/explain — Structured Verdict and receipt JSON
  • POST /v0/chat/stream — Streaming SSE chat and 0-second adapter-toggled Compare Chat
  • POST /v0/addons/{name}/install — Install optional extras with live SSE progress
  • GET /v0/doctor — Hardware, VRAM, and installed extras report

3. Scripts, CI Gates & Exit Codes

Every CLI command supports structured JSON output (--json) and deterministic exit codes:

Exit code Meaning
0 Success (training completed; with --strict-gate, Verdict passed)
2 Refused (invalid recipe/inputs) or blocked by --strict-gate on significant regression
3 Unexpected runtime crash (traceback printed so tool errors are never disguised as policy refusals)

Example CI check that trains, enforces a strict export gate, and writes machine-readable Verdict JSON:

actuator train data/support.jsonl \
  --model Qwen/Qwen3-4B \
  --eval strict \
  --strict-gate \
  --out runs/ci-candidate

actuator explain runs/ci-candidate --json > verdict.json

4. Machine-Readable Reference for Coding Agents (actuator agent-docs)

Working with Claude Code, Codex, Cursor, or another coding agent? Print a compact, token-efficient reference of all Actuator commands, recipe fields, and SDK calls directly to stdout:

actuator agent-docs