Skip to content

REST API

TFD-42 edited this page Aug 10, 2026 · 2 revisions

REST API — drive Wild_Root_Prompt from your own code

The Web UI server exposes a small HTTP API you can drive from any language — useful for wiring Wild_Root_Prompt into another tool, an editor plugin, or a script.

Start the server headless:

python3 prompt_expert_enhance.py web --no-browser

Base URL: http://localhost:7860 (change with --port).

Scope: the server binds to the loopback interface only — it is not reachable from other machines, and has no authentication because it has no remote surface. Keep it that way.

All request bodies are application/json. Every text field is sanitized server-side before it reaches a model.


GET /api/status

Is the model backend reachable?

curl -s http://localhost:7860/api/status
{ "ollama": true }

GET /api/models

Models installed locally.

curl -s http://localhost:7860/api/models
{ "models": [ ... ] }

On failure the array is empty and an error field is included rather than the request failing.


GET /api/templates

The built-in starter templates — see Templates and Bundles.

{ "templates": [ { "id": "...", "title": "...", "category": "...", "task": "..." } ] }

POST /api/preprocess

Restructure a raw task before generating. Returns the rewritten text so you can show it to a user for editing.

Field Required Description
task yes Raw task text
model no Generation model, used as fallback for this step
pre_processor_model no Dedicated (usually smaller/faster) model for this step. Explicit field wins, then the saved setting, then model
curl -s -X POST http://localhost:7860/api/preprocess \
  -H "Content-Type: application/json" \
  -d '{"task": "explain kubernetes to me simply", "model": "llama3.2:3b"}'
{ "result": "…restructured task…" }

An empty task returns {"result": ""} rather than an error.


POST /api/generate

Streams a generation as Server-Sent Events.

Field Required Default Description
task yes Task description. Empty → 400 {"error": "Empty task"}
model no configured model_a Model to generate with
mode no "full" "quick" or "full". Anything else falls back to "full"
draft no false Sections 1–2 only. Ignored unless mode is "full"

Temperature, timeout, technique set, web enrichment, and page summarization all come from settings.json — see Configuration.

curl -s -N -X POST http://localhost:7860/api/generate \
  -H "Content-Type: application/json" \
  -d '{"task": "explain the actor model", "model": "llama3.2:3b", "mode": "quick"}'

Event stream shape

Each SSE frame is data: <json>:

Frame Meaning
{"phase": "researching"} Web enrichment is running (sent first when enrichment is on)
{"phase": "generating"} Generation starting (sent first when enrichment is off)
{"token": "…"} One streamed token
{"done": true} Stream complete
{"token": "\n[ERROR] …"} Error, delivered in-band before the stream closes

The phase frame exists because web research happens synchronously before the first real token — it lets a client show a distinct "researching" state instead of appearing frozen.

Completed generations are also written to outputs/, exactly as the CLI does.


POST /api/synthesize

Merges two manifests into one unified document, streamed the same way.

Field Required Description
manifest_a yes First document text
manifest_b yes Second document text
task no The original task, for context. Defaults to "synthesis"
model no Synthesis model

Either manifest missing → 400 {"error": "Both manifests required"}.


Minimal client

import json, requests

with requests.post(
    "http://localhost:7860/api/generate",
    json={"task": "design a rate limiter", "mode": "quick"},
    stream=True,
) as response:
    for line in response.iter_lines():
        if not line or not line.startswith(b"data: "):
            continue
        event = json.loads(line[6:])
        if event.get("done"):
            break
        if "token" in event:
            print(event["token"], end="", flush=True)

A curl-only walkthrough is in examples/rest_api.sh.


When to use the API vs the CLI

The API covers the everyday path — preprocess, generate, synthesize. Technique bundles, ranges, draft-vs-full control per call, deep research, alternate backends and caching flags are richer on the CLI, which is also the better choice for batch and scripted work since it needs no running server.


Next: Web UI · CLI Reference · Use Cases.

Clone this wiki locally