Skip to main content
POST
/
api
/
v1
/
artifacts
/
generate
curl -X POST https://suite.sundaypyjamas.com/api/v1/artifacts/generate \
  -H "Authorization: Bearer spj_ai_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "insight-narrative-v1",
    "scope": { "level": "organization", "label": "Acme Inc." },
    "period": { "start": "2026-04-01", "end": "2026-06-30" },
    "input": {
      "aggregates": {
        "recordCount": 4210,
        "metrics": { "activeUsers": 1893, "churnRate": 0.042 },
        "breakdowns": [
          { "dimension": "plan", "rows": [ { "key": "pro", "count": 1200 }, { "key": "free", "count": 3010 } ] }
        ]
      },
      "samples": [
        { "id": "u_1", "fields": { "plan": "pro", "lastActive": "2026-06-28" } }
      ],
      "context": { "instructions": "Focus on churn drivers.", "locale": "en-US" }
    }
  }'
{
  "data": {
    "templateId": "insight-narrative-v1",
    "outputSnapshot": {
      "version": 1,
      "generatedAt": "2026-07-08T10:00:00Z",
      "templateId": "insight-narrative-v1",
      "scope": { "level": "organization", "label": "Acme Inc." },
      "period": { "start": "2026-04-01", "end": "2026-06-30" },
      "source": { "type": "customer_payload", "recordCount": 4210, "sampleCount": 1 },
      "llm": {
        "executiveSummary": "Acme's active user base grew steadily through Q2...",
        "insights": [
          {
            "title": "Free-to-pro conversion is slowing",
            "body": "Only 8% of new free users converted to pro this quarter, down from 12%.",
            "category": "implementation_pressure",
            "evidence": ["1200 pro / 4210 total"]
          }
        ],
        "followUpConsiderations": [
          {
            "title": "Investigate onboarding drop-off",
            "body": "Session data suggests most churn happens in the first 7 days.",
            "attentionLevel": "elevated"
          }
        ],
        "confidenceNotes": "Based on a 4210-record sample with moderate breakdown coverage."
      }
    },
    "usage": {
      "model": "google/gemini-2.5-flash",
      "inputTokens": 812,
      "outputTokens": 340,
      "costUsd": 0.0021,
      "providerSlug": "google"
    }
  },
  "meta": { "requestId": "9f2a...", "persisted": false }
}

Request Body

scope
object
required
input
object
required
templateId
string
default:"insight-narrative-v1"
Known values: "insight-narrative-v1", "phabc-data-insights-v1". Returns 400 if unrecognized.
appId
string
UUID of an app in your workspace. Returns 404 if it doesn’t belong to your workspace.
period
object
externalRef
string
External reference ID, tracked in billing. Max 256 chars.
model
string
Override model, e.g. "google/gemini-2.5-flash". Max 200 chars.
The full request body, serialized as JSON, must not exceed 512,000 bytes.

Response

data
object
meta
object
curl -X POST https://suite.sundaypyjamas.com/api/v1/artifacts/generate \
  -H "Authorization: Bearer spj_ai_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "insight-narrative-v1",
    "scope": { "level": "organization", "label": "Acme Inc." },
    "period": { "start": "2026-04-01", "end": "2026-06-30" },
    "input": {
      "aggregates": {
        "recordCount": 4210,
        "metrics": { "activeUsers": 1893, "churnRate": 0.042 },
        "breakdowns": [
          { "dimension": "plan", "rows": [ { "key": "pro", "count": 1200 }, { "key": "free", "count": 3010 } ] }
        ]
      },
      "samples": [
        { "id": "u_1", "fields": { "plan": "pro", "lastActive": "2026-06-28" } }
      ],
      "context": { "instructions": "Focus on churn drivers.", "locale": "en-US" }
    }
  }'
{
  "data": {
    "templateId": "insight-narrative-v1",
    "outputSnapshot": {
      "version": 1,
      "generatedAt": "2026-07-08T10:00:00Z",
      "templateId": "insight-narrative-v1",
      "scope": { "level": "organization", "label": "Acme Inc." },
      "period": { "start": "2026-04-01", "end": "2026-06-30" },
      "source": { "type": "customer_payload", "recordCount": 4210, "sampleCount": 1 },
      "llm": {
        "executiveSummary": "Acme's active user base grew steadily through Q2...",
        "insights": [
          {
            "title": "Free-to-pro conversion is slowing",
            "body": "Only 8% of new free users converted to pro this quarter, down from 12%.",
            "category": "implementation_pressure",
            "evidence": ["1200 pro / 4210 total"]
          }
        ],
        "followUpConsiderations": [
          {
            "title": "Investigate onboarding drop-off",
            "body": "Session data suggests most churn happens in the first 7 days.",
            "attentionLevel": "elevated"
          }
        ],
        "confidenceNotes": "Based on a 4210-record sample with moderate breakdown coverage."
      }
    },
    "usage": {
      "model": "google/gemini-2.5-flash",
      "inputTokens": 812,
      "outputTokens": 340,
      "costUsd": 0.0021,
      "providerSlug": "google"
    }
  },
  "meta": { "requestId": "9f2a...", "persisted": false }
}

Errors

StatusCodeMessage
400INVALID_INPUTSchema validation failure (bad scope.level, unknown templateId, oversized payload)
401Invalid API key
402INSUFFICIENT_CREDITSInsufficient credits. Please purchase additional credits to continue.
404APP_NOT_FOUNDApp not found in this workspace
500The AI model could not produce a valid structured report. Please try again or use a different model.
503No AI model configured