{
  "openapi": "3.1.0",
  "info": {
    "title": "Spawl API",
    "version": "1.0.0",
    "description": "Single-pass structured decisions over a document and a list of multiple-choice questions. Billed at $0.042 per 1M input tokens; output tokens are $0. The document is encoded and billed once per request however many questions it carries. POST /v1/decide and POST /v1/systemone follow the request shapes of Jev, so switching from Jev means changing the base URL.",
    "license": {
      "name": "Apache-2.0 (open weights)"
    }
  },
  "servers": [
    {
      "url": "https://api.spawl.ai"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/decide": {
      "post": {
        "operationId": "decide",
        "summary": "Answer one or more multiple-choice questions about a document",
        "description": "Send a document (premise, or its Jev alias document) and questions. Each question gets one choice with a calibrated confidence. Exactly one of premise and document is required.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DecideRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One decision per question, plus token usage.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DecideResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request body failed validation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          },
          "413": {
            "description": "The request body is too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          },
          "415": {
            "description": "The content type is not application/json.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          },
          "503": {
            "description": "Inference is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/v1/systemone": {
      "post": {
        "operationId": "systemOne",
        "summary": "Jev System One compatible endpoint",
        "description": "Accepts the request and returns the response described by the Jev System One specification (state, questions keyed by id, answers keyed by id). The schema is not repeated here; see Jev's published System One specification. Image bounding-box (box) questions and assets are rejected with 400.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "state",
                  "questions"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Answers keyed by question id, plus token usage.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "answers",
                    "usage"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "The request body failed validation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemOneErrorEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemOneErrorEnvelope"
                }
              }
            }
          },
          "413": {
            "description": "The request body is too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemOneErrorEnvelope"
                }
              }
            }
          },
          "415": {
            "description": "The Content-Type is not JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemOneErrorEnvelope"
                }
              }
            }
          },
          "503": {
            "description": "Inference is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemOneErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "health",
        "summary": "Service health",
        "security": [],
        "responses": {
          "200": {
            "description": "The service is up. ready is false while the inference backend is degraded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer <API key>"
      }
    },
    "schemas": {
      "DecideQuestion": {
        "type": "object",
        "required": [
          "id",
          "instructions",
          "choices"
        ],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^\\s*\\S[\\s\\S]*$",
            "description": "Unique within the request."
          },
          "instructions": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000,
            "pattern": "^\\s*\\S[\\s\\S]*$"
          },
          "choices": {
            "type": "array",
            "minItems": 2,
            "maxItems": 12,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^\\s*\\S[\\s\\S]*$"
            }
          },
          "anchors": {
            "type": "array",
            "minItems": 2,
            "maxItems": 12,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 2000,
              "pattern": "^\\s*\\S[\\s\\S]*$"
            },
            "description": "One description per choice, in the same order. Length must equal choices."
          },
          "mode": {
            "$ref": "#/components/schemas/DecideMode"
          }
        }
      },
      "DecideMode": {
        "type": "string",
        "enum": [
          "auto",
          "1pass",
          "cot"
        ],
        "description": "auto picks a single pass or a chain of thought of up to 48 tokens per question."
      },
      "DecideRequest": {
        "type": "object",
        "required": [
          "questions"
        ],
        "additionalProperties": false,
        "oneOf": [
          {
            "required": [
              "premise"
            ]
          },
          {
            "required": [
              "document"
            ]
          }
        ],
        "properties": {
          "premise": {
            "type": "string",
            "minLength": 1,
            "maxLength": 250000,
            "pattern": "^\\s*\\S[\\s\\S]*$"
          },
          "document": {
            "type": "string",
            "minLength": 1,
            "maxLength": 250000,
            "pattern": "^\\s*\\S[\\s\\S]*$",
            "description": "Jev alias of premise."
          },
          "questions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 64,
            "items": {
              "$ref": "#/components/schemas/DecideQuestion"
            },
            "description": "Question ids must be unique."
          },
          "model": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^\\s*\\S[\\s\\S]*$"
          },
          "mode": {
            "$ref": "#/components/schemas/DecideMode"
          },
          "return_probabilities": {
            "type": "boolean"
          }
        }
      },
      "DecisionResult": {
        "type": "object",
        "required": [
          "id",
          "choice",
          "confidence",
          "mode_used"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "choice": {
            "type": "string"
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "probabilities": {
            "type": "object",
            "additionalProperties": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            }
          },
          "mode_used": {
            "type": "string",
            "enum": [
              "1pass",
              "cot"
            ]
          },
          "reasoning": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "DecideUsage": {
        "type": "object",
        "required": [
          "doc_tokens",
          "question_tokens",
          "input_tokens"
        ],
        "properties": {
          "doc_tokens": {
            "type": "integer",
            "minimum": 0
          },
          "question_tokens": {
            "type": "integer",
            "minimum": 0
          },
          "input_tokens": {
            "type": "integer",
            "minimum": 0,
            "description": "doc_tokens plus question_tokens; the billed amount."
          },
          "output_tokens": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "DecideResponse": {
        "type": "object",
        "required": [
          "model",
          "decisions",
          "usage"
        ],
        "properties": {
          "model": {
            "type": "string"
          },
          "decisions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DecisionResult"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/DecideUsage"
          },
          "latency_ms": {
            "type": "number",
            "minimum": 0
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "required": [
          "ok",
          "ready",
          "service",
          "model",
          "version"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "ready": {
            "type": "boolean"
          },
          "service": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "degraded_reasons": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "SystemOneErrorEnvelope": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "integer",
                "description": "The HTTP status code."
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}