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/mgpt

All 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

HeaderRequiredNotes
AuthorizationyesBearer <api-key>
Content-Typeyes (POST)application/json
X-Request-IdnoOptional caller correlation id, mirrored back in diagnostics.
POST/api/mgpt/responses

Generate 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

FieldTypeRequiredNotes
modelstringyesPublic alias. Currently mdl-1-lite-frozen.
userInputstringyesThe next user message, already serialized by the caller.
universestring (UUID)stored modeUniverse id. Mutually exclusive with universeDoc.
universeDocobjectinline modeFull universe document. Not persisted.
statePointerinteger ≥ 0noBranch cursor, validated server-side before truncation.
requestIdstringnoCaller correlation id surfaced in logs and diagnostics.
gameIdstringnoOptional lookup scope for hosted-game universes.
workspacePreviewbooleannoUse preview/dev hosted resources where relevant.
useStructuredOutputbooleannoRead provider response format from the stored output contract.
useAdditionalInstructionsbooleannoAppend stored additional instructions to the system prompt.
responseFormatobjectnoInline override for the provider response format.
toolsarraynoFunction-calling tool definitions (type: "function", name, parameters).
toolChoicestring | objectno"auto", "none", or { type: "function", name }.
toolResultsarraynoTool results to feed back into the next turn.
userIdstringgateway-setFilled by the platform gateway. Do not send from external clients.
usageForwardobjectgateway-setPlatform usage settlement metadata. Do not send from external clients.

Request modes

  • Stored universeuniverse + 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 universeuniverseDoc + userInput. The document is used for the current request only; nothing is persisted. Useful for development.
  • Standalonemodel + userInput only. 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": [] }
    }
  }'
POST/api/mgpt/universes

Create 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

FieldTypeRequiredNotes
storedPromptstringyesName of the stored prompt file (without extension).
displayNamestringnoHuman-readable label stored on the universe.
userIdstringgateway-setOwning 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"
  }'
POST/api/mgpt/images

Generate 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.

FieldTypeRequiredNotes
sceneUidstringyesGenerated-scene id.
systemPromptstringyesHosted-game image system prompt.
descriptionstringyesMain scene-specific image description from the applied patch.
additionalPromptstringnoShort hosted-game-owned addendum, appended last.
referenceImagesarraynoInterleaved text/image parts for character and location references.
backgroundReferenceobjectnoOptional legacy singular background/location reference.
imageConfigobjectnoimageSize: 1K | 2K | 4K; aspectRatio defaults to 16:9.
modelstringnoDefaults to the public image alias when omitted.
GET/api/mgpt/logs

List logs

List recent generation logs, or fetch a single log when identifier is provided. Required scope: mgpt.logs:read.

Query parameterTypeRequiredNotes
ownerUserIdstringyesOwning user; required for scoping.
kindtext | imagenoRestrict by log kind.
identifierstringnoFetch a single log by id (returns detail instead of a list).
gamestringnoFilter by hosted game id.
userstringnoFilter by acting user.
requestIdstringnoFilter by caller correlation id.
pageinteger ≥ 1no1-indexed page number.
pageSizeinteger 1–100noItems 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" }
StatusMeaningNotes
400Validation errorMissing field, invalid statePointer, conflicting universe/universeDoc. Body includes a errors array for Pydantic validation failures.
401UnauthorizedMissing or invalid bearer token.
403ForbiddenToken lacks the required scope, or the universe is not owned by the calling user.
404Not foundUniverse id does not exist.
5xxProvider / storage failureSafe to retry with the same requestId; retries are de-duplicated.

Scopes

ScopeEndpoints
mgpt.responses:createPOST /responses, POST /universes
mgpt.images:createPOST /images
mgpt.logs:readGET /logs