API Reference · v1
MGPT HTTP API
Endpoint-level reference for the MGPT public surface. Conceptual material — universes, the stateful Responses model, the 64/16 window — lives in the Docs. This page is the field-level contract.
Base URL
The public gateway and the local backend expose the same routes:
# Public gateway
https://mdl.continualmi.com/api/mgpt
# Local development (backend-api)
http://127.0.0.1:8090/backend-api/mgptAll examples on this page use the public gateway. The local backend accepts the same bodies under the /backend-api/mgpt prefix.
Authentication
All endpoints require a bearer token issued from the MGPT API console. Keys have the shape cmi_live_<public>.<secret> and are stored hashed in core.api_keys.
Authorization: Bearer cmi_live_<public>.<secret>The gateway derives the calling user from the key owner. External clients must not send userId or usageForward; the gateway fills those in.
Headers
| Header | Required | Notes |
|---|---|---|
Authorization | yes | Bearer <api-key> |
Content-Type | yes (POST) | application/json |
X-Request-Id | no | Optional caller correlation id, mirrored back in diagnostics. |
/api/mgpt/responsesGenerate response
Generate the next assistant turn. Works in three modes — stored universe, inline universe, or standalone single-turn — selected by which optional fields are present.
Required scope: mgpt.responses:create.
Request body
| Field | Type | Required | Notes |
|---|---|---|---|
model | string | yes | Public alias. Currently mdl-1-lite-frozen. |
userInput | string | yes | The next user message, already serialized by the caller. |
universe | string (UUID) | stored mode | Universe id. Mutually exclusive with universeDoc. |
universeDoc | object | inline mode | Full universe document. Not persisted. |
statePointer | integer ≥ 0 | no | Branch cursor, validated server-side before truncation. |
requestId | string | no | Caller correlation id surfaced in logs and diagnostics. |
gameId | string | no | Optional lookup scope for hosted-game universes. |
workspacePreview | boolean | no | Use preview/dev hosted resources where relevant. |
useStructuredOutput | boolean | no | Read provider response format from the stored output contract. |
useAdditionalInstructions | boolean | no | Append stored additional instructions to the system prompt. |
responseFormat | object | no | Inline override for the provider response format. |
tools | array | no | Function-calling tool definitions (type: "function", name, parameters). |
toolChoice | string | object | no | "auto", "none", or { type: "function", name }. |
toolResults | array | no | Tool results to feed back into the next turn. |
userId | string | gateway-set | Filled by the platform gateway. Do not send from external clients. |
usageForward | object | gateway-set | Platform usage settlement metadata. Do not send from external clients. |
Request modes
- Stored universe —
universe+userInput. The normal path. MGPT loads the universe by id, reads the persisted prompt snapshot and output contract, and applies the 64/16 block window before calling the provider. - Inline universe —
universeDoc+userInput. The document is used for the current request only; nothing is persisted. Useful for development. - Standalone —
model+userInputonly. Single-turn completion against the provider with no persisted state. Useful for smoke tests.
Response body
{
"assistantRaw": "string",
"previewText": "string",
"promptFingerprint": "sha256:...",
"nextUniverseTime": "2026-05-06T12:00:00Z",
"requestLog": { "id": "log_..." },
"usageSettlement": { /* tokens, billing */ },
"timingBreakdown": { "totalMs": 612, "providerMs": 540 },
"diagnostics": {
"summary": { /* totals */ },
"serverStages": [ /* per-stage timings */ ],
"storage": { /* universe load info */ },
"prompt": { /* window selection */ },
"provider": { /* model + provider routing */ }
}
}assistantRaw is the canonical handoff. The remaining fields are optional metadata; persist diagnostics stage names verbatim.
Examples
Standalone:
curl https://mdl.continualmi.com/api/mgpt/responses \
-H "Authorization: Bearer $CONTINUAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mdl-1-lite-frozen",
"userInput": "Write one sentence about Sintra."
}'Stored universe:
curl https://mdl.continualmi.com/api/mgpt/responses \
-H "Authorization: Bearer $CONTINUAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mdl-1-lite-frozen",
"universe": "813671db-dd71-4108-a1e7-76e9f3e2bc98",
"userInput": "Continue from the current state.",
"requestId": "req_001"
}'Inline universe:
curl https://mdl.continualmi.com/api/mgpt/responses \
-H "Authorization: Bearer $CONTINUAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mdl-1-lite-frozen",
"userInput": "hello",
"universeDoc": {
"conversation": [],
"runtime": { "conversation": [] }
}
}'/api/mgpt/universesCreate universe
Create a persistent universe from a server-side stored prompt. The prompt body is loaded from backend-api/prompts/<storedPrompt>.md (or .txt), copied into the universe snapshot, and never returned to the client.
Required scope: mgpt.responses:create.
Request body
| Field | Type | Required | Notes |
|---|---|---|---|
storedPrompt | string | yes | Name of the stored prompt file (without extension). |
displayName | string | no | Human-readable label stored on the universe. |
userId | string | gateway-set | Owning user. Filled by the platform gateway. |
Response body
{
"universe": "813671db-dd71-4108-a1e7-76e9f3e2bc98",
"userId": "eaa0d5f0-81e9-4c79-b6f2-cf7db0cb5d63",
"prompt": {
"storedPrompt": "emwaver-prompt",
"stored": true
}
}curl https://mdl.continualmi.com/api/mgpt/universes \
-H "Authorization: Bearer $CONTINUAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"storedPrompt": "emwaver-prompt",
"displayName": "EMWaver Agent"
}'/api/mgpt/imagesGenerate image
Generated-scene image endpoint, used by MDL gameplay after a text patch requests a specialScene. MGPT assembles the provider image message: system prompt first, then a single user message with ordered parts (references, then description, then additionalPrompt).
Required scope: mgpt.images:create.
| Field | Type | Required | Notes |
|---|---|---|---|
sceneUid | string | yes | Generated-scene id. |
systemPrompt | string | yes | Hosted-game image system prompt. |
description | string | yes | Main scene-specific image description from the applied patch. |
additionalPrompt | string | no | Short hosted-game-owned addendum, appended last. |
referenceImages | array | no | Interleaved text/image parts for character and location references. |
backgroundReference | object | no | Optional legacy singular background/location reference. |
imageConfig | object | no | imageSize: 1K | 2K | 4K; aspectRatio defaults to 16:9. |
model | string | no | Defaults to the public image alias when omitted. |
/api/mgpt/logsList logs
List recent generation logs, or fetch a single log when identifier is provided. Required scope: mgpt.logs:read.
| Query parameter | Type | Required | Notes |
|---|---|---|---|
ownerUserId | string | yes | Owning user; required for scoping. |
kind | text | image | no | Restrict by log kind. |
identifier | string | no | Fetch a single log by id (returns detail instead of a list). |
game | string | no | Filter by hosted game id. |
user | string | no | Filter by acting user. |
requestId | string | no | Filter by caller correlation id. |
page | integer ≥ 1 | no | 1-indexed page number. |
pageSize | integer 1–100 | no | Items per page. |
curl "https://mdl.continualmi.com/api/mgpt/logs?ownerUserId=$USER_ID&kind=text&pageSize=20" \
-H "Authorization: Bearer $CONTINUAL_API_KEY"Errors
Errors return JSON with a detail field and an HTTP status.
{ "detail": "Universe not found" }| Status | Meaning | Notes |
|---|---|---|
400 | Validation error | Missing field, invalid statePointer, conflicting universe/universeDoc. Body includes a errors array for Pydantic validation failures. |
401 | Unauthorized | Missing or invalid bearer token. |
403 | Forbidden | Token lacks the required scope, or the universe is not owned by the calling user. |
404 | Not found | Universe id does not exist. |
5xx | Provider / storage failure | Safe to retry with the same requestId; retries are de-duplicated. |
Scopes
| Scope | Endpoints |
|---|---|
mgpt.responses:create | POST /responses, POST /universes |
mgpt.images:create | POST /images |
mgpt.logs:read | GET /logs |