Remote API
PHOS exposes a versioned, provider-neutral remote API for observing and
controlling its semantic state. Every request passes through
PhosApplicationService: clients never access GPIO, sensor buses, camera
frames, renderer objects, or vendor providers directly.
The base path is /api/v1. The checked-in OpenAPI 3.1 contract
is the detailed schema source; the running server publishes the same contract at
/openapi.json and local Swagger UI at /docs.
Access and authentication
The API shares the Web Admin authentication boundary. Sign in through /login
in the same browser before using Swagger UI. It uses the existing phos_admin
HttpOnly, SameSite session cookie; there is no API token or separate API account.
Unauthenticated /api/... requests receive JSON 401 errors, not login-page
redirects. A session that still must change its initial password receives JSON
403 until that is completed.
This API is an authenticated Web Admin adapter, not an independent bearer-token
integration identity. The /api/v1 blueprint is explicitly exempted from the
Flask-WTF CSRF validator; do not assume the CSRF protection on Web Admin forms
also applies to JSON API mutations. This is a security-review limitation, not
a claim that the session cookie is an API token. See the private Step 12 audit
for source evidence and the recommended separate review.
The listener uses canonical web.host and web.port configuration and requires
a restart after changes. The committed configuration is loopback 127.0.0.1 on
port 8080; do not assume that port when connecting to another installation.
For LAN access, bind deliberately to an appropriate local interface, retain Web
Admin authentication, and place TLS plus any additional access control at a
trusted reverse proxy. Do not expose the listener directly to the Internet.
Examples below use a local listener. They assume an authenticated session cookie
has already been established. For curl, pass that existing cookie with
--cookie "$PHOS_ADMIN_COOKIE"; no credentials are shown or stored here.
curl --cookie "$PHOS_ADMIN_COOKIE" http://127.0.0.1:8080/api/v1/status
curl --cookie "$PHOS_ADMIN_COOKIE" http://127.0.0.1:8080/openapi.json
Read endpoints
Read endpoints use GET; all return JSON except /api/v1/events, which is an
SSE stream.
| Endpoint | Purpose |
|---|---|
/api/v1/status |
Consolidated robot, visual, environmental, motion, health, presence, attention and touch state. |
/api/v1/presence |
Current provider-neutral Presence read model. |
/api/v1/attention |
Current provider-neutral Attention read model and optional target. |
/api/v1/voice |
Voice/STT availability and the last completed transcript; never raw audio. |
/api/v1/observed-expression |
Latest uncertain classifier observation for the selected face. |
/api/v1/state |
Lifecycle state and whether Core is running. |
/api/v1/environment |
Environmental sensor availability and current measurements when available. |
/api/v1/motion |
IMU availability and current semantic motion snapshot. |
/api/v1/health |
Runtime uptime, Python version and subsystem health. |
/api/v1/capabilities |
Discoverable command metadata and observable vocabulary. |
/api/v1/overlay |
Environmental, manual, and resolved ambient-overlay intent. |
/api/v1/config |
Saved and active canonical non-secret configuration. |
/api/v1/settings/mcp |
MCP listener configuration and live listener status; only enabled and port are writable. |
/api/v1/mqtt/discovery/candidates |
Inactive MQTT discovery candidates for administrative review. |
/api/v1/backgrounds/assets |
Safe managed background asset metadata. |
/api/v1/events |
Authenticated Server-Sent Events stream; not JSON and not a WebSocket. |
For example:
curl --cookie "$PHOS_ADMIN_COOKIE" http://127.0.0.1:8080/api/v1/health
curl --cookie "$PHOS_ADMIN_COOKIE" http://127.0.0.1:8080/api/v1/environment
Unavailable, stale, disabled, and warming-up sensor states remain explicit in responses; clients must not treat missing measurements as current data.
Complete /api/v1 operation inventory
The route inventory below is from the registered Flask blueprint. All routes
are behind the Web Admin session authentication boundary. Routes with a JSON
request body require a JSON object and use the common API error envelope;
voice-session start/stop/cancel and overlay deletion do not require a body.
Endpoint-specific validation and response fields are described below and in
the checked-in OpenAPI contract.
The /v1 path is implemented version naming, not a separately documented
backward-compatibility guarantee.
| Method | Path | Purpose |
|---|---|---|
| GET | /api/v1/status |
Consolidated semantic status. |
| GET, PATCH | /api/v1/settings/mcp |
Read MCP listener status; change only enabled/port. |
| GET, POST | /api/v1/state |
Read state; request a supported lifecycle transition. |
| GET | /api/v1/environment |
Environmental availability and measurements. |
| GET | /api/v1/motion |
IMU/motion availability and snapshot. |
| GET | /api/v1/presence |
Provider-neutral presence projection. |
| GET | /api/v1/attention |
Attention state and target projection. |
| GET | /api/v1/voice |
Voice/STT status and last transcript metadata. |
| POST | /api/v1/voice/listen |
Start one explicit finite capture session. |
| POST | /api/v1/voice/stop |
Stop the active capture session. |
| POST | /api/v1/voice/cancel |
Cancel and discard the active session. |
| POST | /api/v1/speak |
Accept/schedule one bounded speech request. |
| GET | /api/v1/observed-expression |
Latest uncertain expression observation. |
| GET | /api/v1/health |
Runtime and subsystem health. |
| GET | /api/v1/capabilities |
Readable vocabulary and writable command metadata. |
| GET, POST, DELETE | /api/v1/overlay |
Read resolved overlays; set or clear a temporary semantic overlay override. |
| GET, PATCH | /api/v1/config |
Read or validate/save canonical non-secret runtime configuration. |
| GET, POST | /api/v1/mqtt/discovery/candidates |
List and administer inactive MQTT discovery candidates. This is an administrative route, not broker topic publishing. |
| GET | /api/v1/backgrounds/assets |
List safe managed background assets. |
| POST | /api/v1/backgrounds |
Configure supported semantic-state backgrounds. |
| POST | /api/v1/expression |
Request a writable semantic expression. |
| POST | /api/v1/visual-source |
Persist and apply a supported semantic visual source. |
| POST | /api/v1/signal |
Request a canonical transient user signal. |
| GET | /api/v1/events |
SSE stream of bounded semantic change events. |
These are 30 registered method/path operations across 24 route paths. The MCP
server and MQTT broker are separate interfaces; Web Admin page actions are not
additional /api/v1 routes. /openapi.json and /docs are authenticated API
documentation surfaces, not members of this blueprint.
Semantic LED signal
POST /api/v1/signal submits only a semantic user-visible signal through the
application service: {"signal":"success"}, warning, error, or
attention. It does not accept LED animation, color, brightness, direction,
or other controller fields. The semantic LED arbiter resolves any hardware
command only after the API boundary; an unavailable external LED controller
does not expose a raw hardware-control endpoint. All four user signals are
transient; persistent error indication belongs to RobotState.ERROR.
Voice capture
POST /api/v1/voice/listen starts one explicit capture session;
POST /api/v1/voice/stop ends it, and POST /api/v1/voice/cancel discards it.
These commands go through the application service and do not expose microphone
or STT-provider controls. Semantic SSE events cover listening, speech edges,
transcription completion, cancellation and safe errors.
GET /api/v1/voice returns enabled, state, listening,
speech_detected, stt_provider, stt_available, language,
last_transcript, last_confidence, last_transcription_at,
last_transcription_duration_ms, and last_error. The lifecycle is idle →
listening → thinking → idle: listening captures/detects speech, thinking runs
STT, and idle is inactive/completed. An empty recognizer result is successful
with last_transcript: null and no error; voice_empty_utterance instead
denotes audio shorter than the configured minimum, while voice_error denotes
a provider/capture failure. Observable event names are
voice_listening_started, voice_speech_started, voice_speech_ended,
voice_transcription_started, voice_transcription_completed,
voice_empty_utterance, voice_session_cancelled, and voice_error.
When local interaction is enabled, PHOS also passes a completed transcript to
the configured deterministic interaction resolver. A recognized command is
executed only when interaction.execution_enabled is true; this is disabled by
default. Only the implemented command catalog is accepted. See
Voice Commands for the exact phrases and limitations.
Speak
POST /api/v1/speak asks the main PHOS runtime to synthesize and play one short
phrase through its configured provider-neutral TTS/playback path. The separate
Web worker never opens an audio device or invokes Piper directly. Text is trimmed,
must be non-empty, and is limited to 500 characters; accepted speech returns
HTTP 202 after the main runtime has atomically accepted and scheduled the
utterance; it does not wait for synthesis or playback to finish. PHOS does not
queue overlapping requests: an active utterance returns
HTTP 409 with tts_busy; disabled or unavailable TTS returns 503 with
tts_unavailable.
curl -X POST http://127.0.0.1:8080/api/v1/speak \
--cookie "$PHOS_ADMIN_COOKIE" \
-H 'Content-Type: application/json' \
-d '{"text":"Hello from PHOS."}'
Presence has no_one, person_present, and reserved person_engaged values.
Attention has idle, acquiring, tracking, and lost values. Target ID is
runtime-local only; position is normalized, and confidence may be null when a
detector did not supply it. These are observation models, not identity or
biometric-recognition APIs.
Observed Expression is independent telemetry, not PHOS's own visual expression
and not a statement of a person's emotion. It returns HTTP 200 with
available: false when no current classified face exists (or its 1.5-second
freshness window has expired); this does not imply that Presence is no_one. When available, confidence is the actual classifier
confidence. observed_expression_changed SSE events are emitted only when
availability or label changes, not for confidence jitter alone.
Touch is physical-input telemetry, not a remote command. Its read model reports
only the last valid completed tap, double_tap, long_press, swipe_left, or
swipe_right; raw pointer movement and startup-splash input are not recorded.
The SSE stream emits the matching edge event name once per completed gesture,
with position, normalized position and duration payload fields.
Capabilities
GET /api/v1/capabilities is the discovery endpoint. observable_states
contains readable runtime vocabulary, including values that cannot be submitted
(for example robot error). commands describes writable operations and their
HTTP method, endpoint, request field(s), and allowed values.
Current semantic command values are:
| Command | Allowed values |
|---|---|
set_robot_state |
idle, listening, thinking, speaking, sleeping |
set_expression |
neutral, happy, curious, surprised, sad, angry, focused, tired, confused, scared, skeptical |
set_visual_source |
manual, environment, state |
set_overlay.temperature |
none, cold, warm |
set_overlay.air_quality |
none, warning, bad |
Use capability metadata rather than hard-coding these values: it is derived from the same application validation rules as the commands.
Semantic commands
All command bodies must be JSON objects. Invalid JSON bodies receive
invalid_request; invalid semantic values receive a structured JSON error of
the form {"error":{"code":...,"message":...,"details":...}} with HTTP
400. A command may also return 503 when the PHOS runtime is unavailable.
Set lifecycle state
POST /api/v1/state
{"state":"sleeping"}
/capabilities lists the stable writable vocabulary; error is observable
only and is rejected as runtime-only. The existing state machine enforces
IDLE → LISTENING → THINKING → SPEAKING → IDLE with its documented sleeping
alternatives, so a skipped transition returns HTTP 409 with
invalid_state_transition and the current/target values. A successful response
is the current robot-state document, for example:
{"state":"sleeping","running":true}
GET /api/v1/state and the robot member of /api/v1/status also include
current, stable writable values and state-dependent allowed_next values.
/api/v1/capabilities exposes the complete stable transition graph under
commands.set_robot_state.transitions; clients use it to disable invalid
targets without removing or reordering the writable options.
curl --cookie "$PHOS_ADMIN_COOKIE" -X POST http://127.0.0.1:8080/api/v1/state \
-H 'Content-Type: application/json' -d '{"state":"sleeping"}'
Trigger expression
POST /api/v1/expression
curl --cookie "$PHOS_ADMIN_COOKIE" -X POST http://127.0.0.1:8080/api/v1/expression \
-H 'Content-Type: application/json' -d '{"expression":"happy"}'
Allowed values are neutral, happy, curious, surprised, sad, angry,
focused, tired, confused, scared, and skeptical. A successful response
is {"expression":"happy"}. A command is persistent manual semantic intent
owned by BehaviorEngine; it remains active until another expression is selected
(normally neutral) and does not mutate RobotState. sleepy and worried
are readable runtime outcomes, not writable commands, and return
unsupported_expression_command; unknown values return invalid_expression.
Set visual source
POST /api/v1/visual-source
curl --cookie "$PHOS_ADMIN_COOKIE" -X POST http://127.0.0.1:8080/api/v1/visual-source \
-H 'Content-Type: application/json' -d '{"source":"environment"}'
Allowed values are manual, environment, and state. The response is, for
example, {"source":"environment"}. Invalid values return
invalid_visual_source.
Configuration
PATCH /api/v1/config validates and persists a partial canonical configuration
document, then applies the reloadable part. GET /api/v1/config returns saved,
active, and pending configuration. Unknown fields and invalid values return
invalid_configuration. See Web Admin for the
configuration model and restart policy. Its body is a partial canonical
RuntimeConfig document rather than a command enum; allowed fields and values
are therefore the canonical configuration schema.
curl --cookie "$PHOS_ADMIN_COOKIE" -X PATCH http://127.0.0.1:8080/api/v1/config \
-H 'Content-Type: application/json' \
-d '{"display":{"base_visual_source":"environment"}}'
A successful response includes saved, reload applied paths, and pending
restart-required paths. Invalid JSON objects return invalid_request; unknown
or invalid configuration fields return invalid_configuration.
Overlay commands
Ambient overlays keep temperature and air-quality channels independent.
GET /api/v1/overlay returns three concepts:
environmental: current sensor-derived intent from environmental interpretation.override: active manual/transient values, plusexpires_atwhen timed.resolved: the intent currently presented after arbitration.
Manual values take precedence over their corresponding environmental channel.
When an override expires, or DELETE /api/v1/overlay clears it, PHOS resolves
again against the current environmental intent—it never restores a cached
value from when the override was created.
Example response:
{
"environmental": {"temperature":"warm","air_quality":"none"},
"override": {"active":false,"temperature":null,"air_quality":null,"expires_at":null},
"resolved": {"temperature":"warm","air_quality":"none"}
}
POST /api/v1/overlay requires at least one of temperature or air_quality.
duration_ms, if supplied, is a positive integer lifetime in milliseconds.
curl --cookie "$PHOS_ADMIN_COOKIE" -X POST http://127.0.0.1:8080/api/v1/overlay \
-H 'Content-Type: application/json' \
-d '{"temperature":"warm","duration_ms":3000}'
curl --cookie "$PHOS_ADMIN_COOKIE" -X POST http://127.0.0.1:8080/api/v1/overlay \
-H 'Content-Type: application/json' \
-d '{"temperature":"cold","air_quality":"warning","duration_ms":5000}'
curl --cookie "$PHOS_ADMIN_COOKIE" -X DELETE http://127.0.0.1:8080/api/v1/overlay
Invalid temperature, air-quality, or duration values return respectively
invalid_overlay_temperature, invalid_overlay_air_quality, or
invalid_overlay_duration; an empty request returns invalid_overlay.
Events
GET /api/v1/events is a Server-Sent Events (SSE) stream, not a WebSocket. It
emits bounded semantic events as type, timestamp, and payload, suppresses
consecutive duplicate payloads, and sends keepalive comments while idle. The
current WSGI deployment does not implement a WebSocket endpoint.
The stream forwards presence_changed, person_entered, person_left,
attention_changed, acquired/lost/changed attention target events,
observed_expression_changed, and expression_reaction_changed in addition to
existing semantic updates. The Web Admin uses these only for its read-only
status display.
curl --cookie "$PHOS_ADMIN_COOKIE" -N http://127.0.0.1:8080/api/v1/events