API Guide

Requests, action output and session management

English · 简体中文

Server · Installation · Configuration

Run the examples from `server/` after installing and starting the service. ## 1. Send the Current Frame The server owns one session and its history/KV cache. Send the **system prompt and current user turn (one frame)** with each request; earlier turns in `messages` are ignored. Prepare `frame.jpg` in the `server/` directory and run this example after the server is ready. The [training prompt template](../sash/assets/default_prompt.txt) requires two replacements: `` is `Adaptive Thinking` for the default mode or `Instant` for `--no-reasoning`; `` is your task. ```python import base64, json, urllib.request from pathlib import Path system = (Path("sash/assets/default_prompt.txt").read_text(encoding="utf-8") .replace("", "Adaptive Thinking") .replace("", "Find the car.")) frame = base64.b64encode(Path("frame.jpg").read_bytes()).decode() body = { "messages": [ {"role": "system", "content": system}, {"role": "user", "content": [ {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + frame}}, ]}, ], "max_tokens": 512, } request = urllib.request.Request("http://localhost:8000/v1/chat/completions", data=json.dumps(body).encode(), headers={"Content-Type": "application/json"}) print(json.load(urllib.request.urlopen(request))["choices"][0]["message"]["content"]) ``` ## 2. Read the Response A reply contains an optional thought followed by one action covering **six 33 ms slices**: ```text <|thought_start|>…<|thought_end|><|action_start|>dx dy wheel<|action_sep|>keys<|action_sep|>…<|action_sep|>keys<|action_end|> ``` `dx dy wheel` is the total mouse movement over the six slices; each slice lists the keys held. `sash.protocol.action_validation.parse_output(reply)` returns `(thought, actions)` or raises `ValueError` for an invalid reply. ## 3. Manage the Session A changed system prompt, `POST /reset`, or 10 seconds of inactivity by default starts a new session. The idle timeout is configurable. One request runs at a time; a concurrent request receives **HTTP 409**.
API endpoints and request options | Endpoint / field | Meaning | |---|---| | `POST /v1/chat/completions` | OpenAI-style chat completion; `stream: true` returns SSE after the entire turn has been validated | | `max_tokens` / `max_completion_tokens` | Output budget; default 512 | | `action_only` | `true` skips thinking for this request; always on with `--no-reasoning` | | `include_reasoning_context` | `true` includes the retained reasoning history in the response; reasoning mode only | | `POST /reset` | Drop the session | | `GET /health` | Engine, mode, cache and kernel status |