{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/scriptgrain-com/json-schema/scriptgrain-com-generation-stream-frame-schema.json",
  "title": "GenerationStreamFrame",
  "description": "One JSON payload carried in a `data:` line of the `text/event-stream` response of `POST /v1/generations`\nwith `stream: true`. The stream is: one `init`, then for each variant `delta` frames followed by a `done`\nor `error` frame (frames of different variants interleave; match on `variant_index`), then the literal\nline `data: [DONE]`, which is not JSON. Em dashes are stripped from content. A `done` frame means the\nvariant is saved and its credit deducted. Streamed drafts get no tell rewrite pass, so no `tells_fixed`.\n",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/scriptgrain-com-openapi.json#/components/schemas/GenerationStreamFrame",
  "oneOf": [
    {
      "type": "object",
      "title": "init",
      "required": [
        "type",
        "variants"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "init"
          ]
        },
        "variants": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "variant_index",
              "variant_axis",
              "generation_id"
            ],
            "properties": {
              "variant_index": {
                "type": "integer",
                "minimum": 0,
                "maximum": 2
              },
              "variant_axis": {
                "type": "string",
                "enum": [
                  "standard",
                  "alternative_opening",
                  "oblique_angle"
                ]
              },
              "generation_id": {
                "allOf": [
                  {
                    "$ref": "#/$defs/Uuid"
                  }
                ],
                "description": "The row this variant is saved to."
              }
            }
          }
        }
      }
    },
    {
      "type": "object",
      "title": "delta",
      "required": [
        "type",
        "variant_index",
        "generation_id",
        "content"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "delta"
          ]
        },
        "variant_index": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2
        },
        "generation_id": {
          "$ref": "#/$defs/Uuid"
        },
        "content": {
          "type": "string",
          "description": "The next piece of text for this variant."
        }
      }
    },
    {
      "type": "object",
      "title": "done",
      "required": [
        "type",
        "variant_index",
        "variant_axis",
        "generation_id",
        "status",
        "word_count",
        "word_count_target",
        "within_tolerance",
        "tolerance_pct",
        "voice_match_score",
        "voice_match_notes"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "done"
          ]
        },
        "variant_index": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2
        },
        "variant_axis": {
          "type": "string",
          "enum": [
            "standard",
            "alternative_opening",
            "oblique_angle"
          ]
        },
        "generation_id": {
          "$ref": "#/$defs/Uuid"
        },
        "status": {
          "type": "string",
          "enum": [
            "drafted"
          ]
        },
        "word_count": {
          "type": "integer"
        },
        "word_count_target": {
          "type": [
            "integer",
            "null"
          ]
        },
        "within_tolerance": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "tolerance_pct": {
          "type": "integer"
        },
        "voice_match_score": {
          "type": [
            "number",
            "null"
          ]
        },
        "voice_match_notes": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    {
      "type": "object",
      "title": "error",
      "required": [
        "type",
        "variant_index",
        "generation_id",
        "message"
      ],
      "description": "The variant produced no content after bounded retries; nothing is saved to it as content and no credit is charged.",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "error"
          ]
        },
        "variant_index": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2
        },
        "generation_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "message": {
          "type": "string"
        }
      }
    }
  ],
  "$defs": {
    "Uuid": {
      "type": "string",
      "format": "uuid",
      "description": "A UUID. Path ids that are not UUID-shaped never match a route (404 `not_found`)."
    }
  }
}