Skip to content

Generative Media API ​

Create image, video, or audio generation requests. Context-aware requests can use the user's saved Chainabit context only while Contextual Memory is enabled.

Use the prerequisites to set TOKEN. Set WORKSPACE_ID to the ID of a workspace you can access; see Workspaces. The examples use an interactive user session.

Create a context run ​

POST /ai/generative-media/context-runs requires context-media access and access to the requested media type. Select the workspace with x-workspace-id. The API resolves the account, person, and workspace from authenticated access; do not include accountId, chainerId, or workspaceId in the JSON body.

bash
curl --fail-with-body -sS -X POST "https://api.chainabit.com/api/v1/ai/generative-media/context-runs" \
  -H "Authorization: Bearer $TOKEN" \
  -H "x-workspace-id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Draw a summary of my saved project activity.",
    "mediaType": "image",
    "generationMode": "context_aware",
    "requestedContextSources": ["chainies", "bits"],
    "aspectRatio": "1:1"
  }'

The supported media types are image, video, and audio. requestedContextSources narrows the context to use; it does not grant permission. Supported source names are profile, preferences, settings, sessions, chainies, bits, memory, workspace, generation_history, and uploaded_media.

An optional sessionId can associate the request with an existing chat session. Use the UUID returned as data.id when creating that session.

Contextual Memory ​

Contextual Memory is controlled by the user's aiMemoryEnabled preference. It is shared with other contextual AI features. There is no separate per-source media-consent setting.

Read the current preference:

bash
curl --fail-with-body -sS "https://api.chainabit.com/api/v1/preferences" \
  -H "Authorization: Bearer $TOKEN"

Disable Contextual Memory:

bash
curl --fail-with-body -sS -X PATCH "https://api.chainabit.com/api/v1/preferences" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"aiMemoryEnabled": false}'

Both preference requests return HTTP 200. The response includes data.aiMemoryEnabled; other preference fields are also returned.

Check the result ​

Creating a context run returns HTTP 201. This status confirms that the request was handled; inspect data.status before using a generated result.

When Contextual Memory is off, the context-aware request above returns permission_required without retrieving personal context or invoking a generation provider. Example response:

json
{
  "data": {
    "jobId": "550e8400-e29b-41d4-a716-446655440010",
    "createdAt": "2026-10-10T10:00:00.000Z",
    "updatedAt": "2026-10-10T10:00:00.000Z",
    "status": "permission_required",
    "mediaType": "image",
    "generationMode": "context_aware",
    "permissionRequired": true,
    "allowedContextSources": [],
    "blockedContextSources": ["chainies", "bits"],
    "errorCode": "PERMISSION_DENIED"
  }
}

A result is available only when the response reports completion and includes resultMediaId. A permission-required response does not contain a generated media ID. Enabling Contextual Memory is a user choice; requesting more context sources cannot override an opt-out.

Built with purpose. chainabit.com