Reference

Server API

The CLI is a thin shell over the local server — most /api/* routes have a CLI wrapper. Agent Mode is web-UI only; prompt builder is also available through ima2 prompt build. This page maps the endpoint groups; for full request and response shapes, see API.md.

Base URL

All endpoints are served locally. The default base is http://localhost:3333; the actual bound port is advertised in ~/.ima2/server.json (prefer backend.url).

Generation

EndpointPurpose
POST /api/generateText-to-image and reference-guided root generation.
POST /api/editImage edit / image-to-image generation.
POST /api/generate/multimodeMultimode batch. Supports async POST (202) + SSE multiplexing.
POST /api/node/generateNode-mode generation and child edits. Supports async POST (202) + SSE multiplexing.
GET /api/node/:nodeIdFetch stored node metadata and asset URL.
GET /api/eventsPersistent SSE multiplex channel for all async generation progress.
POST /api/video/generateVideo generation via Grok (T2V/I2V/Ref2V). Supports async POST (202) + SSE multiplexing.
POST /api/video/editVideo-to-video edit via Grok; saves a generated MP4 artifact.
POST /api/video/extendExtend a generated or remote MP4 from its last frame.
GET /api/video/frameExtract a PNG frame from a generated MP4.
POST /api/video/analyzeAnalyze first/last frames from a generated MP4 with Grok 4.3 vision.

POST /api/generate — request body

{
  "prompt": "a shiba in space",
  "quality": "medium",
  "size": "1024x1024",
  "format": "png",
  "moderation": "low",
  "provider": "oauth",
  "model": "gpt-5.4",
  "references": [],
  "requestId": "optional-client-id"
}

Quality: low, medium, high. Moderation: auto, low. Provider: auto, oauth, api, grok, grok-api, agy, gemini-api. Recommended OpenAI model gpt-5.4; app default gpt-5.4-mini. Grok image models: grok-imagine-image and grok-imagine-image-quality. Gemini API models: nano-banana-2 (default) and nano-banana-pro. The web UI uses GET /api/events (SSE multiplexing) for all generation progress: POST routes accept { async: true, requestId } and respond 202; events (phase, partial, done, error) are multiplexed through the shared event bus. CLI clients that send Accept: text/event-stream still receive per-request SSE.

Video generation. POST /api/video/generate (SSE) generates videos via Grok. Models: grok-imagine-video and canonical grok-imagine-video-1.5; grok-imagine-video-1.5-preview is accepted only as a compatibility alias. Modes: text-to-video, image-to-video, reference-to-video (2–7 refs). 1080p is available only for 1.5 image-to-video with one image/frame source; Ref2V, V2V edit, and extension remain base-model paths. CLI: ima2 video. Extended CLI/API surfaces include ima2 video edit, ima2 video extend, ima2 video frame, and ima2 video analyze. Request body accepts plannerModel (default grok-4.3) and storyboard for sequential clip continuity. Frame/analyze accept generated MP4 files; analyze rejects arbitrary remote URLs.

History

EndpointNotes
GET /api/historyList generated assets; ?groupBy=session groups by session title.
DELETE /api/history/:filenameTombstone a generated asset.
POST /api/history/:filename/restoreRestore a recently deleted asset.

Sessions & graphs

EndpointNotes
GET /api/sessions · POST /api/sessionsList or create graph sessions.
GET /api/sessions/:idLoad a session and its graph.
PATCH /api/sessions/:id · DELETE /api/sessions/:idRename or delete a session.
PUT /api/sessions/:id/graphSave a graph snapshot.
Optimistic concurrency. Graph saves require an If-Match header with the current version. A stale version returns GRAPH_VERSION_CONFLICT plus the current version — it only means you saved against a stale snapshot, not that another tab changed the graph.

Agent Mode & discovery

Agent Mode is a conversational image workspace (sessions, turns, and a durable per-session queue). These routes are always registered but have no CLI wrapper — drive Agent Mode from the web UI.

EndpointPurpose
GET /api/capabilitiesAgent-facing discovery: supported models, valid values, limits, version (ima2 capabilities).
GET · POST /api/agent/sessionsList or create agent sessions.
GET · PATCH · DELETE /api/agent/sessions/:idLoad, update, or delete a session.
POST /api/agent/sessions/:id/turnsRun an agent turn; supports slash commands and /question.
GET · POST /api/agent/sessions/:id/queueInspect or enqueue durable queue work (/api/agent/queue/:itemId/cancel · retry manage items).
POST /api/prompt-builder/chatPrompt-builder assistant (ima2 prompt build).

Health, storage & jobs

EndpointNotes
GET /api/healthHealth check (ima2 ping).
GET /api/providersProvider availability and runtime ports (ima2 providers).
GET /api/oauth/statusOAuth proxy status (ima2 oauth status).
GET /api/grok/statusBundled progrok status and xAI model probe (ima2 grok status).
GET /api/storage/statusStorage inspection.
POST /api/storage/open-generated-dirOpen the generated directory in the OS file manager.
GET /api/inflight · DELETE /api/inflight/:idList or force-remove in-flight jobs.

Keys & auth

EndpointNotes
GET /api/keys/statusKey status for all providers (openai, xai, gemini, vertex) — masked key and source.
PUT /api/keys/:providerSave and validate an API key for openai, xai, or gemini. Validates against the provider API before saving to config.
DELETE /api/keys/:providerRemove a config-layer API key (env-sourced keys are immutable).
PUT /api/keys/vertexSave and validate a Google Cloud service-account JSON for Vertex AI auth. Sets geminiAuthMode: "vertex" in config.
DELETE /api/keys/vertexRemove the Vertex AI service-account from config.
GET /api/quotaUsage bars for Codex (GPT OAuth) and Grok. Grok result includes billing.usedUsd / billing.limitUsd for the dollar display.
POST /api/auth/switchStart a device-code auth flow for grok or codex. Returns sessionId, userCode, and verificationUrl.
GET /api/auth/switch/:sessionIdPoll auth flow status: pending, complete, error, or expired.

Common error codes

CodeMeaning
API_KEY_REQUIREDAPI path requested without a configured key.
INVALID_IMAGE_MODELModel name is unknown or unsupported.
IMAGE_MODEL_UNSUPPORTEDModel exists but cannot use image generation.
SAFETY_REFUSAL · MODERATION_REFUSEDUpstream safety / moderation refusal.
AUTH_CHATGPT_EXPIREDCodex/ChatGPT OAuth session expired.
AUTH_API_KEY_INVALIDAPI key is invalid, revoked, or out of quota.
NETWORK_FAILEDNetwork, proxy, VPN, or firewall failure.
OAUTH_UNAVAILABLELocal OAuth proxy is not available.
GRAPH_VERSION_CONFLICTSave made against a stale graph version.
NODE_NOT_FOUNDNode metadata was not found.
GROK_REF_TOO_MANYGrok request included more than three total input images.
GROK_MASK_UNSUPPORTEDGrok edit was requested with a mask.
INVALID_GROK_IMAGE_MODELGrok request used an unsupported image model.
GROK_RATE_LIMITED · GROK_AUTH_FAILEDxAI rate-limit or auth failure through progrok.
GROK_SEARCH_TIMEOUT · GROK_PLANNER_TIMEOUT · GROK_IMAGE_TIMEOUTOne Grok phase exceeded its timeout budget.
GEMINI_API_KEY_MISSINGGemini API provider requested without a configured API key or Vertex AI credentials.
INVALID_GEMINI_API_IMAGE_MODELGemini API model is not one of the valid values (nano-banana-2, nano-banana-pro).
GENERATION_TIMEOUTGemini API generation timed out (120s limit).
The full endpoint → CLI mapping, reference-image error codes, and style-sheet routes are in API.md.