{
  "openapi": "3.1.0",
  "info": {
    "title": "Curva API",
    "version": "1.0.0",
    "summary": "Typed decisions with calibrated probabilities, from any LLM.",
    "description": "The public HTTP API of `curva serve`. Contract v1 is frozen: changes are additive only (new optional fields), never removals or renames. Clients should ignore fields they don't know.\n\nOnce the server has API keys, every route except `GET /health`, `GET /dashboard` and `GET /openapi.json` needs `Authorization: Bearer curva_…`. Every response carries `x-request-id` (the request's own header when it is 1–64 visible ASCII characters, else a new id).",
    "license": {
      "name": "Curva Free License"
    }
  },
  "servers": [
    {
      "url": "http://localhost:7777",
      "description": "curva serve (default port)"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "tags": [
    {
      "name": "decisions",
      "description": "Ask typed questions about a state"
    },
    {
      "name": "calibration",
      "description": "Feedback, calibration reports, drift and the audit log"
    },
    {
      "name": "meta",
      "description": "Health, models, metrics and this document"
    },
    {
      "name": "library",
      "description": "Files, collections, jobs and find"
    },
    {
      "name": "voice",
      "description": "Live listening to a call over a WebSocket, with triggers and actions"
    },
    {
      "name": "video",
      "description": "Live video over a WebSocket: a change gate, vision-model decisions, triggers and actions"
    }
  ],
  "paths": {
    "/v1/files": {
      "post": {
        "tags": [
          "library"
        ],
        "operationId": "uploadFile",
        "summary": "Upload a file to the library",
        "description": "`multipart/form-data` with the file in a part named `file`. The body is streamed to disk, never held in memory, and is not bound by `--max-body-mb` or the 120 s request deadline; the project's library limit (`--library-mb`) applies instead. The type is read from the bytes, not the name. The same bytes uploaded again in the same project return the same id; another project gets an id of its own.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Project"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The stored file",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                },
                "example": {
                  "id": "file_3f9a1c0b7d2e4a6b8c9d0e1f",
                  "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
                  "bytes": 5610783,
                  "mime": "application/pdf",
                  "name": "msa-2024.pdf"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "description": "`too_large`: the project's files would pass its library limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/files/{id}": {
      "delete": {
        "tags": [
          "library"
        ],
        "operationId": "deleteFile",
        "summary": "Delete a file, its items, cards and vectors",
        "description": "The stored bytes go too once no project holds them.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The file id",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Project"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "example": {
                  "id": "file_3f9a1c0b7d2e4a6b8c9d0e1f",
                  "deleted": true
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/collections/{name}": {
      "get": {
        "tags": [
          "library"
        ],
        "operationId": "getCollection",
        "summary": "A collection's items and how far each was read",
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Collection name: 1–64 letters, digits, `_`, `-` or `.`",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Project"
          }
        ],
        "responses": {
          "200": {
            "description": "The collection",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Collection"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "delete": {
        "tags": [
          "library"
        ],
        "operationId": "deleteCollection",
        "summary": "Delete a collection with its items, cards and vectors",
        "description": "Its running jobs are cancelled. The files stay (delete them with `DELETE /v1/files/{id}`).",
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Collection name: 1–64 letters, digits, `_`, `-` or `.`",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Project"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "example": {
                  "name": "contracts",
                  "deleted": true,
                  "items": 3
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/collections/{name}/items": {
      "post": {
        "tags": [
          "library"
        ],
        "operationId": "addItems",
        "summary": "Add files to a collection; a job reads them",
        "description": "Creates the collection if needed. Each PDF page's text layer (or each 60 lines of a text file) becomes cards of about 200–400 words that never cross a page, indexed for keywords (BM25) and meaning (local embeddings, downloaded once). Pages with no text layer are recorded as needing OCR. Each picture becomes one card (caption, objects with boxes, text in it, people, colours, scene, quality) from a vision model, up to 8 pictures a call; a picture this project already has a card for is not sent again. A file already in the collection is skipped. Follow the job with `GET /v1/jobs/{id}`.",
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Collection name: 1–64 letters, digits, `_`, `-` or `.`",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ItemsRequest"
              },
              "example": {
                "files": [
                  "file_3f9a1c0b7d2e4a6b8c9d0e1f"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The job that reads the files",
            "content": {
              "application/json": {
                "example": {
                  "job": "job_5b2e8c1d0a3f4e6b7c8d9e0f",
                  "collection": "contracts",
                  "project": "default"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/collections/{name}/estimate": {
      "post": {
        "tags": [
          "library"
        ],
        "operationId": "estimate",
        "summary": "What reading these files would take and cost",
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Collection name: 1–64 letters, digits, `_`, `-` or `.`",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ItemsRequest"
              },
              "example": {
                "files": [
                  "file_3f9a1c0b7d2e4a6b8c9d0e1f"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The estimate. For a video, `pages` is the most key frames it can have (one every 2 s), `cost_usd` their price, and `video_seconds` its length",
            "content": {
              "application/json": {
                "example": {
                  "collection": "contracts",
                  "files": 1,
                  "bytes": 5610783,
                  "pages": 2131,
                  "cost_usd": 0.0
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/jobs/{id}": {
      "get": {
        "tags": [
          "library"
        ],
        "operationId": "getJob",
        "summary": "How far a library job is",
        "description": "`done` and `total` count pages. A job left running when the server stopped resumes from its last finished page when it starts again.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The job id",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Project"
          }
        ],
        "responses": {
          "200": {
            "description": "The job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                },
                "example": {
                  "id": "job_5b2e8c1d0a3f4e6b7c8d9e0f",
                  "status": "running",
                  "done": 812,
                  "total": 2000,
                  "eta_ms": 9400,
                  "cost_usd": 0.0,
                  "max_cost_usd": null,
                  "error": null
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "delete": {
        "tags": [
          "library"
        ],
        "operationId": "cancelJob",
        "summary": "Cancel a job",
        "description": "It stops after the batch it is reading; the half-read item keeps no cards.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The job id",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Project"
          }
        ],
        "responses": {
          "200": {
            "description": "The job, cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/find": {
      "post": {
        "tags": [
          "library"
        ],
        "operationId": "find",
        "summary": "Find passages and pictures in a collection, in milliseconds and for free",
        "description": "Keyword (BM25) and meaning (vector) results merged by reciprocal rank fusion. Pictures are found through their cards. No model is called, so `cost_usd` is 0, unless `verify` checks the picture hits with a vision model. `took_ms` is measured inside the engine and includes `verify`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FindRequest"
              },
              "example": {
                "collection": "contracts",
                "query": "penalty for late payment",
                "k": 10,
                "filter": {
                  "file": "file_3f9a1c0b7d2e4a6b8c9d0e1f",
                  "pages": [
                    100,
                    400
                  ],
                  "kind": [
                    "text"
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The best passages first",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FindResponse"
                },
                "example": {
                  "hits": [
                    {
                      "item": "itm_8d1e2f3a4b5c6d7e8f9a0b1c",
                      "file": "file_3f9a1c0b7d2e4a6b8c9d0e1f",
                      "name": "msa-2024.pdf",
                      "page": 212,
                      "bbox": null,
                      "snippet": "…**interest** on overdue sums…",
                      "score": 0.83,
                      "match": [
                        "vector",
                        "keyword"
                      ]
                    }
                  ],
                  "took_ms": 1.8,
                  "cost_usd": 0.0
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "tags": [
          "decisions"
        ],
        "operationId": "chatCompletions",
        "summary": "Curva Router: an OpenAI-compatible chat endpoint that picks the model",
        "description": "Send an OpenAI chat-completions body with `\"model\": \"curva/router\"`. Curva routes on the latest user turn and a short summary of the conversation, using the models in `CURVA_ROUTER` or in the request's `curva` object, and forwards the body unchanged except `model` (and `reasoning_effort` when the chosen model sets `effort`). An unsure router sends the request to `default`; a conversation keeps its model unless the router is at least `switch_at` sure; a provider that fails before the reply starts is replaced by the next best model once. Feedback `correct: true/false` on the reply's decision id teaches Curva which model answers which requests; with 30 outcomes per cheaper model, the cheapest model whose learned chance meets `target_accuracy` answers, with no model call to route. `stream: true` passes the provider's server-sent events through. The reply is the provider's, plus a `curva` object (non-streaming) and `x-curva-route`, `x-curva-model`, `x-curva-why`, `x-curva-confidence`, `x-curva-decision` and `x-curva-route-ms` headers. See site/guides/router.md.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "const": "curva/router"
                  },
                  "messages": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": [
                        "role"
                      ]
                    }
                  },
                  "stream": {
                    "type": "boolean"
                  },
                  "curva": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "models": {
                        "type": "object",
                        "additionalProperties": {
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "object",
                              "additionalProperties": false,
                              "properties": {
                                "model": {
                                  "type": "string"
                                },
                                "about": {
                                  "type": "string"
                                },
                                "effort": {
                                  "enum": [
                                    "none",
                                    "minimal",
                                    "low",
                                    "medium",
                                    "high",
                                    "xhigh"
                                  ]
                                }
                              }
                            }
                          ]
                        }
                      },
                      "default": {
                        "type": "string"
                      },
                      "min_confidence": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "switch_at": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "target_accuracy": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "route_ms": {
                        "type": "integer",
                        "minimum": 50,
                        "maximum": 120000
                      },
                      "router": {
                        "type": "string"
                      },
                      "debias": {},
                      "project": {
                        "type": "string"
                      },
                      "conversation": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 512
                      },
                      "receipt": {
                        "type": "boolean"
                      }
                    }
                  }
                },
                "additionalProperties": true
              },
              "example": {
                "model": "curva/router",
                "messages": [
                  {
                    "role": "user",
                    "content": "What is the capital of France?"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The chosen model's reply, with `curva` saying which model answered and why (or its server-sent events when `stream` is true)",
            "content": {
              "application/json": {
                "example": {
                  "id": "chatcmpl-1",
                  "object": "chat.completion",
                  "model": "mistral.ministral-3-8b-instruct",
                  "choices": [
                    {
                      "index": 0,
                      "message": {
                        "role": "assistant",
                        "content": "Paris."
                      },
                      "finish_reason": "stop"
                    }
                  ],
                  "curva": {
                    "route": "small",
                    "model": "@bedrock/mistral.ministral-3-8b-instruct",
                    "provider": "bedrock",
                    "effort": null,
                    "why": "routed",
                    "confidence": 0.93,
                    "decision": "dec_19a0c1f2b3d000004",
                    "cached": false,
                    "route_ms": 412.6,
                    "fallback_from": null,
                    "cost_usd": 4e-05
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/ModelError"
          }
        }
      }
    },
    "/v1/decide": {
      "post": {
        "tags": [
          "decisions"
        ],
        "operationId": "decide",
        "summary": "Answer typed questions about a state",
        "description": "All questions are answered in one model call (twice when debiased). Answers keep the order of `questions`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DecideRequest"
              },
              "examples": {
                "support_ticket": {
                  "summary": "Route a support ticket",
                  "value": {
                    "state": {
                      "ticket": "I was charged twice for A-104, refund please"
                    },
                    "questions": {
                      "department": {
                        "type": "choice",
                        "instructions": "Which team should handle this",
                        "options": {
                          "billing": "Payments, refunds",
                          "technical": "Bugs",
                          "sales": "Pricing"
                        },
                        "min_confidence": 0.8
                      },
                      "frustration": {
                        "type": "score",
                        "instructions": "How frustrated the customer is",
                        "levels": [
                          "Calm",
                          "Frustrated but civil",
                          "Very angry"
                        ]
                      },
                      "refund_requested": {
                        "type": "noul",
                        "instructions": "The customer explicitly asks for a refund"
                      }
                    },
                    "project": "support"
                  }
                },
                "cascade": {
                  "summary": "Cheapest model first, escalate unsure answers",
                  "value": {
                    "model": {
                      "cascade": [
                        "vendor/small-model",
                        "vendor/large-model"
                      ],
                      "escalate_below": 0.8
                    },
                    "state": "The app crashes on launch since the update",
                    "questions": {
                      "bug": {
                        "type": "noul",
                        "instructions": "This reports a software bug"
                      }
                    }
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "request"
                ],
                "properties": {
                  "request": {
                    "type": "string",
                    "description": "The JSON request; must be the first part"
                  }
                },
                "additionalProperties": {
                  "type": "string",
                  "format": "binary",
                  "description": "A file an asset names with `part`"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Typed answers",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DecideResponse"
                },
                "example": {
                  "id": "dec_19294a3c1f2000000",
                  "model": "inclusionai/ling-3.0-flash-fin:free",
                  "project": "support",
                  "config": "curva-1.1.0",
                  "mode": "logprobs",
                  "latency_ms": 1144,
                  "wall_ms": 1151,
                  "cost_usd": 0.0,
                  "cached": false,
                  "debiased": true,
                  "answers": {
                    "department": {
                      "choice": "billing",
                      "probabilities": {
                        "billing": 0.9999,
                        "technical": 0.0,
                        "sales": 0.0001,
                        "none_of_these": 0.0
                      },
                      "confidence": 0.9999,
                      "abstain": false,
                      "calibrated": false
                    },
                    "frustration": {
                      "score": 0.65,
                      "probabilities": [
                        0.36,
                        0.62,
                        0.02
                      ],
                      "confidence": 0.62,
                      "calibrated": false
                    },
                    "refund_requested": {
                      "noul": 0.999,
                      "calibrated": false
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/ModelError"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/v1/systemone": {
      "post": {
        "tags": [
          "decisions"
        ],
        "operationId": "decideCompatible",
        "summary": "Compatible alias of /v1/decide in the `criteria` shape",
        "description": "The same decision as `/v1/decide`, in the `criteria` request shape many typed-decision clients already send, so they work by changing only their base URL. Choice: `criteria` = key → description (text, `null` or JSON), and no escape option unless the question sets `escape: true`. Score: `criteria` = level descriptions, lowest first. Noul: optional `criteria: {\"true\": ..., \"false\": ...}`. `instructions` may be omitted or JSON. `model`: `curva-x.y.z` / `curva-latest` selects that config; a name without a provider prefix means the server default; anything else is as in `/v1/decide`. Every other `/v1/decide` field passes through.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompatRequest"
              },
              "example": {
                "model": "curva-latest",
                "state": {
                  "ticket": "charged twice"
                },
                "questions": {
                  "tone": {
                    "type": "choice",
                    "instructions": "Tone?",
                    "criteria": {
                      "calm": null,
                      "angry": "shouting, capitals"
                    }
                  },
                  "urgency": {
                    "type": "score",
                    "criteria": [
                      "can wait",
                      "today"
                    ]
                  },
                  "spam": {
                    "type": "noul",
                    "instructions": "Spam?",
                    "criteria": {
                      "true": "advertising"
                    }
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "request"
                ],
                "properties": {
                  "request": {
                    "type": "string",
                    "description": "The JSON request; must be the first part"
                  }
                },
                "additionalProperties": {
                  "type": "string",
                  "format": "binary",
                  "description": "A file an asset names with `part`"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The `/v1/decide` response plus `usage`; each answer gains `type`, and a Score's `probabilities` and `legend` are keyed by level",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompatResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/ModelError"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/v1/ask-file": {
      "post": {
        "tags": [
          "decisions"
        ],
        "operationId": "askFile",
        "summary": "Read an ask file, or write one from plain words",
        "description": "An ask file is Markdown: a `## heading` per thing to look for, a sentence under it, and optional bullets (`- not:`, `- alert:`, `- choice:`, `- score:`, `- text`, `- webhook:`, `- if <reading> <op> <value>`). Send its text as `ask` on /v1/decide, /v1/listen or /v1/watch. This route shows what Curva understood from a file with no model call (`cost_usd` 0), or, for plain words, has the model write the file once (one call, a second only when the first file does not parse) and returns it to save and edit.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "additionalProperties": false,
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "An ask file (at most 32 KB), or plain words of at most 2000 characters"
                  },
                  "model": {
                    "$ref": "#/components/schemas/ModelSpec"
                  },
                  "project": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "text": "tell me when smoke appears or someone falls"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "What Curva understood",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "markdown": {
                      "type": "string"
                    },
                    "title": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "questions": {
                      "type": "object",
                      "additionalProperties": {
                        "$ref": "#/components/schemas/Question"
                      }
                    },
                    "triggers": {
                      "type": "object",
                      "additionalProperties": {
                        "$ref": "#/components/schemas/Trigger"
                      }
                    },
                    "summary": {
                      "type": "string",
                      "description": "Each rule in plain words"
                    },
                    "written": {
                      "type": "boolean",
                      "description": "True when the model wrote the file from plain words"
                    },
                    "cost_usd": {
                      "type": "number"
                    },
                    "decisions": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Not JSON, or an unknown field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "The file does not parse (the message names the line and the fix), or the words could not be turned into a file",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/deliveries": {
      "get": {
        "tags": [
          "decisions"
        ],
        "operationId": "listDeliveries",
        "summary": "The delivery log of actions, newest first",
        "description": "Every attempt to send a fired action to a webhook, Slack, Teams, Discord or Telegram, per project. The newest 10,000 deliveries a project are kept, for up to 30 days. CLI: `curva webhook log`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Project"
          },
          {
            "name": "status",
            "in": "query",
            "description": "Only `failed` or only `delivered`; leave it out for both",
            "schema": {
              "type": "string",
              "enum": [
                "failed",
                "delivered"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Deliveries per page (clamped to 1 to 500)",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The deliveries",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "project",
                    "deliveries"
                  ],
                  "properties": {
                    "project": {
                      "type": "string"
                    },
                    "deliveries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "project",
                          "action",
                          "kind",
                          "to",
                          "status",
                          "attempts",
                          "latency_ms",
                          "created_at",
                          "updated_at"
                        ],
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "`dlv_...`"
                          },
                          "project": {
                            "type": "string"
                          },
                          "action": {
                            "type": "string",
                            "description": "The action's id, sent as `x-curva-idempotency-key`"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "webhook",
                              "slack",
                              "teams",
                              "discord",
                              "telegram"
                            ]
                          },
                          "to": {
                            "type": "string",
                            "description": "The destination's scheme and host only; the path of a chat URL is its token, so the full URL is kept encrypted with `CURVA_MASTER_KEY`"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "delivered",
                              "failed"
                            ]
                          },
                          "attempts": {
                            "type": "integer",
                            "description": "Attempts so far, replays included"
                          },
                          "last_error": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Why the last attempt failed, without the URL"
                          },
                          "latency_ms": {
                            "type": "integer"
                          },
                          "created_at": {
                            "type": "integer",
                            "description": "Unix ms"
                          },
                          "updated_at": {
                            "type": "integer",
                            "description": "Unix ms"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "The API key is limited to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/deliveries/{id}/replay": {
      "post": {
        "tags": [
          "decisions"
        ],
        "operationId": "replayDelivery",
        "summary": "Send a logged delivery again",
        "description": "Sends the same body to the same destination with the same `x-curva-idempotency-key`, signed again with a fresh `t`, and adds the attempt to the delivery's row. Needs `CURVA_MASTER_KEY`, which keeps the full URL encrypted; without it deliveries are logged but cannot be replayed (422). CLI: `curva webhook replay <id>`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The delivery id, `dlv_...`, from GET /v1/deliveries",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The delivery after the new attempt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "project",
                    "action",
                    "kind",
                    "to",
                    "status",
                    "attempts",
                    "latency_ms",
                    "created_at",
                    "updated_at"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "`dlv_...`"
                    },
                    "project": {
                      "type": "string"
                    },
                    "action": {
                      "type": "string",
                      "description": "The action's id, sent as `x-curva-idempotency-key`"
                    },
                    "kind": {
                      "type": "string",
                      "enum": [
                        "webhook",
                        "slack",
                        "teams",
                        "discord",
                        "telegram"
                      ]
                    },
                    "to": {
                      "type": "string",
                      "description": "The destination's scheme and host only; the path of a chat URL is its token, so the full URL is kept encrypted with `CURVA_MASTER_KEY`"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "delivered",
                        "failed"
                      ]
                    },
                    "attempts": {
                      "type": "integer",
                      "description": "Attempts so far, replays included"
                    },
                    "last_error": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Why the last attempt failed, without the URL"
                    },
                    "latency_ms": {
                      "type": "integer"
                    },
                    "created_at": {
                      "type": "integer",
                      "description": "Unix ms"
                    },
                    "updated_at": {
                      "type": "integer",
                      "description": "Unix ms"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "The API key is limited to another project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/listen": {
      "get": {
        "tags": [
          "voice"
        ],
        "operationId": "listen",
        "summary": "Listen to a live call and act on it (WebSocket)",
        "description": "Upgrade to a WebSocket. The first message is JSON `start`; then the caller's side of the call goes up as binary audio frames (pcm16 little-endian at 16 or 8 kHz, or μ-law at 8 kHz, 20–100 ms each, at most 256 KiB a frame), and `{\"type\": \"stop\"}` ends it. Curva cuts the audio into utterances (an energy detector: 600 ms of silence ends one, a long one is cut every 4 s), sends each to an upstream live model as it arrives, and answers every utterance with a `decision` event: `{\"type\": \"decision\", \"utterance\", \"id\", \"answers\", \"latency_ms\", \"forced\"}`, plus `\"fallback\": true` when the model missed `deadline_ms` or the key was over its rate. Each trigger whose `if` holds at `min_p` or above fires once per call: `{\"type\": \"action\", \"name\", \"id\", \"because\", \"utterance\", \"decision\"}`, also POSTed to its `webhook` when it has one, signed with the project's webhook secret (`x-curva-signature: sha256=<HMAC-SHA256 of the body>`, `x-curva-idempotency-key: <action id>`; retried up to 3 times under the same id). After `stop` comes `{\"type\": \"receipt\", \"call\", \"utterances\", \"decisions\", \"actions\", \"fallbacks\", \"median_latency_ms\"}` and the socket closes. A problem is sent as `{\"type\": \"error\", \"error\": {\"type\", \"message\"}}`; one in `start` closes the socket. The API key goes in `start` as `key` or in the `Authorization` header, never in the URL; the key's rate counts once per utterance. Without keys, a page on another site cannot open the socket (403). A call with no message for 30 s is closed. On a video call, camera frames go up as `{\"type\": \"frame\", \"data_base64\"}` (JPEG, PNG or WebP, at most 2 MiB) and `start` may name a `vision_model`: each utterance is then answered a second time from the transcript and the newest frame, as a `decision` with `\"seen\": true`, `frame`, `frame_sha256` and `changed`. Every decision is in the audit log with its `call` and the actions it fired, and `POST /v1/feedback` with `call` labels them all.",
        "parameters": [
          {
            "name": "Upgrade",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "websocket"
              ]
            }
          }
        ],
        "responses": {
          "101": {
            "description": "Switching to the WebSocket protocol. Messages are described in `ListenStart` and `ListenEvent`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListenStart"
                },
                "example": {
                  "type": "start",
                  "key": "curva_…",
                  "call": "call_123",
                  "sample_rate": 16000,
                  "encoding": "pcm16",
                  "ask": "scam",
                  "deadline_ms": 1500,
                  "fallback": {
                    "pressure": false,
                    "impersonation": false,
                    "asks_for_money_or_code": false,
                    "synthetic_voice": false,
                    "verdict": "warn"
                  },
                  "triggers": {
                    "warn_user": {
                      "if": {
                        "@verdict": "warn"
                      },
                      "min_p": 0.7
                    },
                    "end_call": {
                      "if": {
                        "@verdict": "block"
                      },
                      "min_p": 0.9,
                      "webhook": "https://app.example/hooks/end"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "A server without API keys refuses a socket opened by a page on another site"
          }
        }
      }
    },
    "/v1/watch": {
      "get": {
        "tags": [
          "video"
        ],
        "operationId": "watch",
        "summary": "Watch a live video stream and act on it (WebSocket)",
        "description": "Upgrade to a WebSocket. The first message is JSON `start`; then frames go up as binary messages (JPEG, PNG or WebP, at most 2 MiB each), `{\"type\": \"state\", ...}` replaces the readings merged into every later frame's state (vehicle speed, a zone name), and `{\"type\": \"stop\"}` ends the stream. Frames are never queued: a change gate (a 64×64 grey thumbnail compared with the last frame kept, with a threshold that follows the scene's own noise, plus one frame every `max_quiet_s`) drops unchanged frames, at most one vision-model decision is in flight per stream, and a frame that arrives while one is waiting replaces it (counted as `dropped`). Every frame the gate drops gets a `decision` with `\"tier\": \"gate\"` repeating the last answers; a frame the local model answers (when the server has one) gets `\"tier\": \"local\"` within milliseconds, and its actions go out first, before that decision is signed and written, with `\"confirmed\": false`; a frame the hosted model judges gets `\"tier\": \"model\"` with `id`, `answers`, `latency_ms` from the frame's arrival and the signed `receipt`, plus `\"fallback\": true` when the model missed `deadline_ms` or the key was over its rate. The hosted model runs in the background and never holds up the next frame; when it answers, each action fired speculatively from a local answer gets a `confirmed` or `retracted` event with `after_ms`, also POSTed to the trigger's webhook (idempotency key `<action id>.confirmed` or `.retracted`). A trigger fires when its `if` holds at `min_p` or above on k of the last n judged frames (`confirm`, default 2 of 3) or on one frame at `min_p_single` (default 0.95), and again after it held on none of the last n: `{\"type\": \"action\", \"name\", \"id\", \"because\", \"frame\", \"at_ms\", \"decision\"}`, also POSTed to its `webhook` signed with the project's webhook secret. After `stop` comes `{\"type\": \"receipt\", \"stream\", \"frames\", \"gated\", \"sent_to_model\", \"dropped\", \"refused\", \"local\", \"cached\", \"reused\", \"cropped\", \"decisions\", \"actions\", \"checked\", \"unconfirmed\", \"fallbacks\", \"rate_limited\", \"fired\", \"confirmed\", \"retracted\", \"median_latency_ms\", \"median_check_ms\"}` (plus `audits`, `heads` and `local_latency_ms` when the server has the local model) and the socket closes. With the local model (`curva vision-model fetch`), each camera (`stream` name, per project) learns a head per yes/no question from the hosted model's answers and, once its answers agree with the hosted model at least 95% of the time, answers familiar frames alone; such a frame is not sent to the hosted model unless it fired an action (to be confirmed) or is one of about one in 20 sampled as a check. A change of the whole picture sends the camera's heads back to shadowing. `POST /v1/feedback` on a watch decision's `id` teaches the camera too. The API key goes in `start` as `key` or in the `Authorization` header; the key's rate counts once per model decision. A stream with no frame for 30 s is closed. Pull mode: `\"source\": \"rtsp://...\"` (or `rtsps`, `http`, `https`) in `start` has the server read the camera with ffmpeg at `fps` instead of taking frames; only public addresses are read, checked at `start` and for every connection ffmpeg opens, unless the server owner allows a network with `CURVA_WATCH_ALLOW`; a camera that drops is reopened up to 6 times, and one that cannot be read ends the stream with a `source_error` and the receipt (with `source`, shown without user name, password or query). The `start` message may be 64 KiB and other text 32 KiB.",
        "parameters": [
          {
            "name": "Upgrade",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "websocket"
              ]
            }
          }
        ],
        "responses": {
          "101": {
            "description": "Switching to the WebSocket protocol. Messages are described in `WatchStart` and `WatchEvent`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WatchStart"
                },
                "example": {
                  "type": "start",
                  "key": "curva_…",
                  "stream": "cam_7",
                  "ask": "driving",
                  "fps": 5,
                  "deadline_ms": 1500,
                  "fallback": {
                    "no_belt": false,
                    "phone_in_hand": false,
                    "eyes_closed": false,
                    "no_helmet": false
                  },
                  "state": {
                    "speed_kmh": 42
                  },
                  "triggers": {
                    "no_belt": {
                      "if": {
                        "@no_belt": true
                      },
                      "min_p": 0.8,
                      "webhook": "https://app.example/hooks/belt"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/feedback": {
      "post": {
        "tags": [
          "calibration"
        ],
        "operationId": "feedback",
        "summary": "Record the true answer for one question of a past decision",
        "description": "From 30 labels for the same exact question in a project, a calibrator is fitted and future answers come back with `calibrated: true` whenever it makes them more accurate. Sending feedback again for the same decision and question replaces the earlier label. Skipped and rule-answered questions are not stored, so feedback for them gets 404.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FeedbackRequest"
              },
              "example": {
                "decision_id": "dec_19294a3c1f2000000",
                "question": "department",
                "label": "billing"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Label recorded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FeedbackResponse"
                },
                "example": {
                  "decision_id": "dec_19294a3c1f2000000",
                  "question": "department",
                  "labels": 31,
                  "min_labels": 30,
                  "calibrated": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidJson"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/calibration": {
      "get": {
        "tags": [
          "calibration"
        ],
        "operationId": "calibration",
        "summary": "Calibration report for the most recent wording of a question",
        "parameters": [
          {
            "$ref": "#/components/parameters/Question"
          },
          {
            "$ref": "#/components/parameters/Project"
          },
          {
            "name": "model",
            "in": "query",
            "description": "The model whose answers to report: a calibrator is fitted on one model's answers and applied only to that model's. The model that answered the question last by default",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "target",
            "in": "query",
            "description": "A promised accuracy, strictly between 0.5 and 1 (422 otherwise, and for a noul or multi question): adds `promise`, the threshold that a question with this `target_accuracy` is decided by right now",
            "schema": {
              "type": "number",
              "exclusiveMinimum": 0.5,
              "exclusiveMaximum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Before (raw) and after (held-out calibrated) quality",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CalibrationResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadQuery"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/audit": {
      "get": {
        "tags": [
          "calibration"
        ],
        "operationId": "audit",
        "summary": "Every decision, newest first",
        "description": "The state itself is never stored, only its SHA-256. Pass `next_before` as `before` for the next page.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Project"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Entries per page (clamped to 1–1000)",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 1000
            }
          },
          {
            "name": "before",
            "in": "query",
            "description": "A decision id: return only older entries",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "call",
            "in": "query",
            "description": "Return only the decisions sent with this `call` id (same order and paging)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "node",
            "in": "query",
            "description": "Return only the decisions sent with this `node` name (same order and paging). With `call` as well, only the decisions that match both",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One page of the audit log",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuditResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadQuery"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/summary": {
      "get": {
        "tags": [
          "calibration"
        ],
        "operationId": "summary",
        "summary": "Decisions, spend and speed of a project",
        "description": "Adds up the audit log over the last UTC days, today included: in total, per UTC day, per model and per node (`by_node`: one row per `node` name that decisions or missed deadlines were sent with; decisions without a node are in none of its rows). `timed` and `late` say how many requests with a `deadline_ms` were answered in time and how many missed it; the share answered in time is `timed / (timed + late)`. A day or model with only missed deadlines still gets a row, with `decisions: 0`; a missed deadline is counted under the first model of its plan. The built-in dashboard reads this.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Project"
          },
          {
            "name": "days",
            "in": "query",
            "description": "UTC days to add up, counting today (clamped to 1–1825)",
            "schema": {
              "type": "integer",
              "default": 30,
              "minimum": 1,
              "maximum": 1825
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Usage of the project",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "project": {
                      "type": "string"
                    },
                    "days": {
                      "type": "integer"
                    },
                    "totals": {
                      "type": "object",
                      "properties": {
                        "decisions": {
                          "type": "integer"
                        },
                        "cached": {
                          "type": "integer",
                          "description": "Decisions served from the cache, with no model call"
                        },
                        "cost_usd": {
                          "type": "number"
                        },
                        "latency_ms": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "Mean `latency_ms` (model time only) of the decisions that were not served from the cache; `null` without any"
                        },
                        "wall_ms": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "Mean `wall_ms` (the whole time a decision took) of the decisions that were not served from the cache and have one; `null` without any, as when every decision is from before `wall_ms` was recorded"
                        },
                        "timed": {
                          "type": "integer",
                          "description": "Decisions that carried a `deadline_ms` and were answered within it"
                        },
                        "late": {
                          "type": "integer",
                          "description": "Requests that missed their `deadline_ms` (504 `deadline`); they are not decisions and count nowhere else"
                        }
                      }
                    },
                    "by_day": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "type": "object",
                            "properties": {
                              "day": {
                                "type": "string"
                              }
                            }
                          },
                          {
                            "type": "object",
                            "properties": {
                              "decisions": {
                                "type": "integer"
                              },
                              "cached": {
                                "type": "integer",
                                "description": "Decisions served from the cache, with no model call"
                              },
                              "cost_usd": {
                                "type": "number"
                              },
                              "latency_ms": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Mean `latency_ms` (model time only) of the decisions that were not served from the cache; `null` without any"
                              },
                              "wall_ms": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Mean `wall_ms` (the whole time a decision took) of the decisions that were not served from the cache and have one; `null` without any, as when every decision is from before `wall_ms` was recorded"
                              },
                              "timed": {
                                "type": "integer",
                                "description": "Decisions that carried a `deadline_ms` and were answered within it"
                              },
                              "late": {
                                "type": "integer",
                                "description": "Requests that missed their `deadline_ms` (504 `deadline`); they are not decisions and count nowhere else"
                              }
                            }
                          }
                        ]
                      }
                    },
                    "by_model": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "type": "object",
                            "properties": {
                              "model": {
                                "type": "string"
                              }
                            }
                          },
                          {
                            "type": "object",
                            "properties": {
                              "decisions": {
                                "type": "integer"
                              },
                              "cached": {
                                "type": "integer",
                                "description": "Decisions served from the cache, with no model call"
                              },
                              "cost_usd": {
                                "type": "number"
                              },
                              "latency_ms": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Mean `latency_ms` (model time only) of the decisions that were not served from the cache; `null` without any"
                              },
                              "wall_ms": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Mean `wall_ms` (the whole time a decision took) of the decisions that were not served from the cache and have one; `null` without any, as when every decision is from before `wall_ms` was recorded"
                              },
                              "timed": {
                                "type": "integer",
                                "description": "Decisions that carried a `deadline_ms` and were answered within it"
                              },
                              "late": {
                                "type": "integer",
                                "description": "Requests that missed their `deadline_ms` (504 `deadline`); they are not decisions and count nowhere else"
                              }
                            }
                          }
                        ]
                      }
                    },
                    "by_node": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "type": "object",
                            "properties": {
                              "node": {
                                "type": "string"
                              }
                            }
                          },
                          {
                            "type": "object",
                            "properties": {
                              "decisions": {
                                "type": "integer"
                              },
                              "cached": {
                                "type": "integer",
                                "description": "Decisions served from the cache, with no model call"
                              },
                              "cost_usd": {
                                "type": "number"
                              },
                              "latency_ms": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Mean `latency_ms` (model time only) of the decisions that were not served from the cache; `null` without any"
                              },
                              "wall_ms": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Mean `wall_ms` (the whole time a decision took) of the decisions that were not served from the cache and have one; `null` without any, as when every decision is from before `wall_ms` was recorded"
                              },
                              "timed": {
                                "type": "integer",
                                "description": "Decisions that carried a `deadline_ms` and were answered within it"
                              },
                              "late": {
                                "type": "integer",
                                "description": "Requests that missed their `deadline_ms` (504 `deadline`); they are not decisions and count nowhere else"
                              }
                            }
                          }
                        ]
                      }
                    },
                    "learned": {
                      "type": "object",
                      "description": "Decisions Curva answered by itself (`learned`) over the same days",
                      "properties": {
                        "decisions": {"type": "integer"},
                        "share": {"type": "number", "description": "Of all decisions"},
                        "saved_usd": {"type": "number", "description": "Those decisions times the mean cost of an uncached model decision"},
                        "questions": {"type": "array", "description": "Each learned question: `fingerprint`, `trained_at`, and `shadowed` and `agreed`, the answers given beside the model and how many matched it"}
                      }
                    },
                    "voice": {
                      "type": "object",
                      "description": "Calls listened to through `/v1/listen` over the same days",
                      "properties": {
                        "calls": {
                          "type": "integer"
                        },
                        "decisions": {
                          "type": "integer",
                          "description": "Utterances answered, fallbacks included"
                        },
                        "missed": {
                          "type": "integer",
                          "description": "Utterances answered with the fallback"
                        },
                        "median_ms": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "description": "Median time from the end of an utterance to its answer; `null` without any"
                        },
                        "actions": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "integer"
                          },
                          "description": "Actions fired, by name"
                        }
                      }
                    },
                    "projects": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Projects with decisions that this key may read"
                    },
                    "library": {
                      "type": ["object", "null"],
                      "description": "The project's library: documents and pictures read, pages indexed, how many searches this server has run since it started (the last 1,000 of all projects are kept) and their median time inside the engine, and what reading cost over these days. `null` on a server without a library",
                      "properties": {
                        "documents": {"type": "integer"},
                        "pictures": {"type": "integer"},
                        "pages": {"type": "integer"},
                        "searches": {"type": "integer"},
                        "search_ms_median": {"type": ["number", "null"]},
                        "reading_usd": {"type": "number"}
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadQuery"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/drift": {
      "get": {
        "tags": [
          "calibration"
        ],
        "operationId": "drift",
        "summary": "One question's raw answers per ISO week (UTC), oldest first",
        "description": "Weeks without decisions are left out. The latest week (when earlier weeks exist) adds `mix_change`, `confidence_change` and `drift`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Question"
          },
          {
            "$ref": "#/components/parameters/Project"
          },
          {
            "name": "weeks",
            "in": "query",
            "description": "ISO weeks to report, counting the current one (clamped to 1–53)",
            "schema": {
              "type": "integer",
              "default": 8,
              "minimum": 1,
              "maximum": 53
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Weekly answer mix and confidence",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DriftResponse"
                },
                "example": {
                  "project": "default",
                  "question": "department",
                  "weeks": [
                    {
                      "week": "2026-W38",
                      "decisions": 120,
                      "mix": {
                        "billing": 0.6,
                        "technical": 0.4
                      },
                      "confidence": 0.91
                    },
                    {
                      "week": "2026-W39",
                      "decisions": 95,
                      "mix": {
                        "billing": 0.3,
                        "technical": 0.7
                      },
                      "confidence": 0.88,
                      "mix_change": 0.3,
                      "confidence_change": -0.03,
                      "drift": true
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadQuery"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "models",
        "summary": "`curva-latest`, every pinned config, and the server's default model",
        "description": "The names `/v1/systemone` accepts as `model` besides provider model ids, and `default_model`: the model a request without `model` uses, with the default it replaced and when.",
        "responses": {
          "200": {
            "description": "Configs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelsResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/receipts/keys": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "receiptKeys",
        "summary": "The public keys that sign decision receipts, newest first",
        "description": "Open without an API key: public keys hold no secret. Keys rotated out stay listed so their receipts still verify.",
        "security": [],
        "responses": {
          "200": {
            "description": "Public keys",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "keys"
                  ],
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "public",
                          "created_at"
                        ],
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "The first 16 hex characters of the SHA-256 of the public key; a receipt names it as `key`"
                          },
                          "public": {
                            "type": "string",
                            "description": "Ed25519 public key, 32 bytes in hex"
                          },
                          "created_at": {
                            "type": "integer",
                            "description": "Unix ms"
                          },
                          "retired_at": {
                            "type": ["integer", "null"],
                            "description": "Unix ms when a newer key started signing (the first server start after `curva receipt rotate`); null for the key in use. A receipt signed with this key and dated after it does not verify"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "health",
        "summary": "Liveness check",
        "security": [],
        "responses": {
          "200": {
            "description": "The server is up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "version"
                  ],
                  "properties": {
                    "status": {
                      "const": "ok"
                    },
                    "version": {
                      "type": "string",
                      "examples": [
                        "0.3.1"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/metrics": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "metrics",
        "summary": "Prometheus metrics",
        "description": "`curva_decisions_total`, `curva_cache_hits_total`, `curva_answers_total`, `curva_abstains_total`, the `curva_decide_duration_seconds` histogram, `curva_http_responses_total{status}` and, with `CURVA_DAILY_LIMIT`, `curva_daily_quota_remaining`.",
        "responses": {
          "200": {
            "description": "Prometheus text format 0.0.4",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/dashboard": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "dashboard",
        "summary": "Self-contained HTML dashboard",
        "description": "The page holds no data, so it is served without a key; its API calls send the key the user pastes.",
        "security": [],
        "responses": {
          "200": {
            "description": "HTML page",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "openapi",
        "summary": "This OpenAPI document",
        "description": "Served without a key: it describes the API and contains no data.",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "A Curva API key (`curva_…`) from `curva keys create`. Not needed when the server has no keys."
      }
    },
    "parameters": {
      "Question": {
        "name": "question",
        "in": "query",
        "required": true,
        "description": "The question key",
        "schema": {
          "type": "string"
        }
      },
      "Project": {
        "name": "project",
        "in": "query",
        "description": "Calibration namespace",
        "schema": {
          "type": "string",
          "default": "default"
        }
      }
    },
    "responses": {
      "InvalidJson": {
        "description": "`invalid_json`: the body is not JSON, or has an unknown `mode` or question `type`",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "invalid_json",
                "message": "unknown variant `fast`, expected one of `auto`, `logprobs`, `verbal`"
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "`unauthorized`: the server has API keys and none (or an unknown or revoked one) was sent",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "unauthorized",
                "message": "send `Authorization: Bearer <Curva API key>`"
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "`not_found`: unknown decision or question",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooLarge": {
        "description": "`too_large`: the body is over the server's limit (`curva serve --max-body-mb`, default 16)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "InvalidRequest": {
        "description": "`invalid_request`: the request or a question is invalid; the message names the problem (and the question)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "invalid_request",
                "message": "images[0]: the data is not valid base64"
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "`rate_limited`: this API key is over its requests per minute, the model provider is rate-limiting, or the server's daily limit is spent",
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ModelError": {
        "description": "`model_error`: every model in the chain failed after retries; `model_unavailable`: the model isn't available to the server's provider account",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Timeout": {
        "description": "`timeout`: the request took longer than 120 s",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "BadQuery": {
        "description": "A query parameter is missing or malformed (plain-text body)",
        "content": {
          "text/plain": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    },
    "schemas": {
      "File": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "bytes": {
            "type": "integer"
          },
          "mime": {
            "type": "string",
            "description": "Read from the bytes"
          },
          "name": {
            "type": "string",
            "description": "The uploaded file name, kept as a label only"
          }
        }
      },
      "ItemsRequest": {
        "type": "object",
        "required": [
          "files"
        ],
        "properties": {
          "files": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "maxItems": 1000,
            "description": "File ids from `POST /v1/files`: PDF, plain text, or PNG, JPEG, WebP or GIF pictures"
          },
          "project": {
            "type": "string",
            "default": "default"
          },
          "max_cost_usd": {
            "type": "number",
            "minimum": 0,
            "description": "Stop the job before a call would pass this spend; the job then ends `stopped`. Reading text is free; pictures are paid vision calls"
          },
          "model": {
            "type": "string",
            "description": "The vision model that describes pictures (default: the server's `--model`), e.g. `@gemini/gemini-3.1-flash-lite`"
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "failed",
              "cancelled",
              "stopped"
            ]
          },
          "done": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "eta_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "cost_usd": {
            "type": "number"
          },
          "max_cost_usd": {
            "type": [
              "number",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Collection": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "project": {
            "type": "string"
          },
          "cards": {
            "type": "integer"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "file": {
                  "type": "string"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "pdf",
                    "text",
                    "image"
                  ]
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "queued",
                    "running",
                    "done",
                    "failed",
                    "cancelled",
                    "stopped"
                  ]
                },
                "pages": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "cards": {
                  "type": "integer"
                },
                "ocr_pages": {
                  "type": "integer",
                  "description": "Pages with no text layer, left for OCR"
                },
                "error": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "job": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "FindRequest": {
        "type": "object",
        "required": [
          "collection",
          "query"
        ],
        "properties": {
          "collection": {
            "type": "string"
          },
          "query": {
            "type": "string",
            "maxLength": 2000
          },
          "k": {
            "type": "integer",
            "default": 10,
            "minimum": 1,
            "maximum": 100
          },
          "project": {
            "type": "string",
            "default": "default"
          },
          "filter": {
            "type": "object",
            "properties": {
              "file": {
                "type": "string",
                "description": "Only this file id"
              },
              "pages": {
                "type": "array",
                "items": {
                  "type": "integer"
                },
                "minItems": 2,
                "maxItems": 2,
                "description": "First and last page, inclusive"
              },
              "kind": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Card kinds: `text` or `image`"
              }
            }
          },
          "verify": {
            "description": "Check each picture hit with its pixels: a yes-or-no question as text, or `{\"type\": \"noul\" or \"box\", \"instructions\": ...}`. The hits go to the vision model 8 to a decision, through the decision path (calibration, cache, audit); each gets `p` (and `box` for a box question) and the list comes back most likely first. With verify, `k` is at most 24 and `cost_usd` is what the decisions cost",
            "oneOf": [
              {"type": "string"},
              {"type": "object", "required": ["type", "instructions"], "properties": {"type": {"type": "string", "enum": ["noul", "box"]}, "instructions": {"type": "string"}}}
            ]
          },
          "model": {
            "type": "string",
            "description": "The vision model for `verify` (default: the server's)"
          }
        }
      },
      "FindResponse": {
        "type": "object",
        "properties": {
          "took_ms": {
            "type": "number"
          },
          "cost_usd": {
            "type": "number"
          },
          "hits": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "item": {
                  "type": "string"
                },
                "file": {
                  "type": "string",
                  "description": "The file id"
                },
                "name": {
                  "type": "string",
                  "description": "The file name"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "text",
                    "image",
                    "video"
                  ]
                },
                "page": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "description": "1-based; null for a picture or a video"
                },
                "at_ms": {
                  "type": "integer",
                  "description": "A video only: when its key frame was taken, in milliseconds from the start"
                },
                "end_ms": {
                  "type": "integer",
                  "description": "A video only: when the next key frame was taken, or the end of the video"
                },
                "bbox": {
                  "type": [
                    "array",
                    "null"
                  ],
                  "items": {
                    "type": "number"
                  },
                  "description": "Left, top, right, bottom as 0–1 fractions. A picture: the box of the object the query names, when its card has one. A page: null while PDF text is read without positions"
                },
                "snippet": {
                  "type": "string",
                  "description": "The matched words between `**`, or the passage's start"
                },
                "score": {
                  "type": "number",
                  "description": "0–1, from reciprocal rank fusion"
                },
                "match": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "vector",
                      "keyword"
                    ]
                  }
                },
                "p": {
                  "type": "number",
                  "description": "With `verify`: the calibrated probability that the picture fits"
                },
                "box": {
                  "description": "With a box `verify`: where it is in the picture",
                  "oneOf": [
                    {"$ref": "#/components/schemas/Edges"},
                    {"type": "null"}
                  ]
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "invalid_json",
                  "unauthorized",
                  "not_found",
                  "too_large",
                  "invalid_request",
                  "rate_limited",
                  "model_error",
                  "model_unavailable",
                  "timeout",
                  "internal"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          },
          "answers": {
            "type": "object",
            "description": "When a decision fails at the model (502, 504, or 429 from the provider): the answers that needed no model, rule answers and skipped questions, as in a decision's `answers`. Absent when there are none.",
            "additionalProperties": {
              "$ref": "#/components/schemas/Answer"
            }
          }
        }
      },
      "ModelSpec": {
        "description": "Which model(s) answer. Defaults to the server's `--model` (or the pinned config's model when `config` is set).",
        "oneOf": [
          {
            "type": "string",
            "description": "A model id: `vendor/model` goes to the default provider (OpenRouter), `@<provider>/<model>` to a named one",
            "examples": [
              "inclusionai/ling-3.0-flash-fin:free",
              "@ollama/qwen3:4b"
            ]
          },
          {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "description": "Fallback chain, tried in order until one answers"
          },
          {
            "type": "object",
            "description": "2–5 models answer concurrently and are blended; answers get `agreement`",
            "required": [
              "council"
            ],
            "additionalProperties": false,
            "properties": {
              "council": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 2,
                "maxItems": 5
              }
            }
          },
          {
            "type": "object",
            "description": "Cheapest first; only questions answered below `escalate_below` go to the next model; answers get `answered_by`",
            "required": [
              "cascade"
            ],
            "additionalProperties": false,
            "properties": {
              "cascade": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 1
              },
              "escalate_below": {
                "type": "number",
                "minimum": 0,
                "maximum": 1,
                "default": 0.8
              }
            }
          },
          {
            "type": "object",
            "description": "Asked at once; the first valid answer wins",
            "required": [
              "race"
            ],
            "additionalProperties": false,
            "properties": {
              "race": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 1
              }
            }
          },
          {
            "type": "object",
            "description": "The first model is asked; each `after_ms` without a valid answer, the next model is asked as well (at once when a model fails). The first valid answer wins, the others are cancelled, and `model` in the response names the model that answered. `latency_ms` includes the wait before that model was asked",
            "required": [
              "hedge"
            ],
            "additionalProperties": false,
            "properties": {
              "hedge": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 2,
                "maxItems": 5
              },
              "after_ms": {
                "type": "integer",
                "minimum": 10,
                "maximum": 10000,
                "default": 150
              }
            }
          },
          {
            "type": "object",
            "description": "Autopilot: a hedge that the server arranges itself. The models are ordered by how fast each has been answering, the fastest first, and the next one is asked after one and a half times the leader's usual time. A model not measured in the last five minutes is tried first once",
            "required": [
              "auto"
            ],
            "additionalProperties": false,
            "properties": {
              "auto": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 2,
                "maxItems": 5
              }
            }
          }
        ]
      },
      "DecideRequest": {
        "type": "object",
        "required": [
          "state"
        ],
        "properties": {
          "ask": {
            "description": "A question set built into the server, asked in place of `questions`: `check` (state `{action, policy?, context?, requester?, approved?}`, answers `check`: allow or block; without a policy, or with a blank one, the default applies: an action that cannot be undone or moves money needs `approved: true`, which only your app sets, and nothing in `context` counts as approval; `approved` must be true or false), `spoken` (state: what was just said in a voice call, answers `verdict`), `guard` (the guardrails recipe), `signals` (the voice-call recipe), the call-audio sets `hear`, `scam`, `support`, `sales`, `booking`, `consent`, `verify`, `health` and `collections` (their recipes), `auto` (no questions of your own: `happening`, `attention`, `event` and `where`, a Box that on a video also carries `at_ms`; the default on `/v1/watch` and when a request has a `video` asset and no `questions` or `ask`), or `next` (answers `next`: one of your actions, or `done`). Send the name, or an object to set `min_confidence` (default 0.8) and, for `next`, `actions`",
            "oneOf": [
              {
                "type": "string",
                "enum": ["check", "guard", "spoken", "signals", "next", "hear", "scam", "support", "sales", "booking", "consent", "verify", "health", "collections", "emotion", "auto"]
              },
              {
                "type": "string",
                "description": "The text of an ask file: Markdown with a `## heading` and a sentence for each thing to look for (see /v1/ask-file)"
              },
              {
                "type": "object",
                "required": ["name"],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "enum": ["check", "guard", "spoken", "signals", "next", "hear", "scam", "support", "sales", "booking", "consent", "verify", "health", "collections", "emotion", "auto"]
                  },
                  "min_confidence": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "default": 0.8
                  },
                  "actions": {
                    "type": "object",
                    "description": "For `next`: each action's name and what it does",
                    "additionalProperties": {
                      "type": "string"
                    }
                  }
                }
              }
            ]
          },
          "state": {
            "description": "Any JSON (string, object or array) to decide about. At most 150,000 bytes of JSON (about 32k tokens; a character outside the Latin alphabet takes 2 to 4 bytes)."
          },
          "questions": {
            "type": "object",
            "description": "1–64 questions, key → question. Order is kept in the response.",
            "minProperties": 1,
            "maxProperties": 64,
            "additionalProperties": {
              "$ref": "#/components/schemas/Question"
            }
          },
          "model": {
            "$ref": "#/components/schemas/ModelSpec"
          },
          "mode": {
            "type": "string",
            "enum": [
              "auto",
              "logprobs",
              "verbal"
            ],
            "default": "auto",
            "description": "`auto`: logprobs if the model returns them, else verbal"
          },
          "debias": {
            "description": "Ask with the options in original and reversed order and average (default `true`). `\"auto\"` stops asking the reversed order once a (model, question) has shown no position bias.",
            "oneOf": [
              {
                "type": "boolean"
              },
              {
                "const": "auto"
              }
            ],
            "default": true
          },
          "think": {
            "type": "boolean",
            "default": false,
            "description": "Let the model reason briefly before answering. Always verbal mode (`mode: logprobs` gets 422); slower and costlier."
          },
          "project": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "default": "default",
            "description": "Calibration namespace. Feedback and calibrators are kept per project."
          },
          "config": {
            "type": "string",
            "description": "A pinned config (`curva-1.0.0`, `curva-1.1.0`, `curva-1.2.0`) or `curva-latest` (the default). Fields set on the request still win. See `GET /v1/models`.",
            "examples": [
              "curva-latest",
              "curva-1.2.0"
            ]
          },
          "privacy": {
            "type": "string",
            "enum": [
              "standard",
              "strict"
            ],
            "default": "standard",
            "description": "`strict`: only providers that neither store nor train on prompts"
          },
          "explain": {
            "type": "boolean",
            "default": false,
            "description": "Add `explain: {field: drop in probability}` to each answer (leave-one-out over at most 12 top-level fields of an object `state`, one extra call per field). Not with `depends_on` (422)"
          },
          "learn": {
            "type": "boolean",
            "default": false,
            "description": "Keep this decision's state on the server (at most 2,000 bytes of JSON, for 180 days). Once the decision has feedback, the state and its true answer are shown to the model as an example for the same question in the same project: up to 4 per question, corrections and every label first. Not with `privacy: strict`, `images`, `assets` or `explain`"
          },
          "learned": {
            "type": "boolean",
            "default": false,
            "description": "Let Curva answer a question by itself, with no model call and at no cost, once it has learned it: at least 200 labelled decisions sent with `learn`, both answers among the labels, held-out accuracy at least the model's on the same labels, and 30 answers given beside the model first. Answered only at or above the question's `min_confidence` (or its `target_accuracy` threshold; 0.9 otherwise); such answers have `answered_by: learned`. It turns itself off when recent labels contradict it. Questions with `depends_on`, and requests with `images`, `assets` or `sources`, always go to the model. Default: off, or on with `curva serve --learned`"
          },
          "sources": {
            "type": "object",
            "required": ["collection"],
            "description": "Answer from a library collection. Curva finds the `k` best passages for each question's wording and the state, puts them in the prompt with ids, and asks in verbal mode; each answer gets `evidence`, the passages the model said it rests on, checked against what was sent. An answer resting on none is marked `abstain: true`. Only the found passages are sent and paid for. `look` also sends the pictures of the top 4 picture hits; PDF pages have no images yet",
            "properties": {
              "collection": {"type": "string"},
              "k": {"type": "integer", "minimum": 1, "maximum": 50, "default": 8},
              "look": {"type": "boolean", "default": false}
            }
          },
          "brief": {
            "type": "boolean",
            "default": false,
            "description": "Ask the model to list only each question's likely labels instead of a probability for every label. The reply is shorter, so the decision is faster; labels the model leaves out share the remaining probability. Only changes verbal answers (logprobs answers are already one letter per question). Part of the cache key"
          },
          "deadline_ms": {
            "type": "integer",
            "minimum": 50,
            "maximum": 120000,
            "description": "Answer within this many milliseconds or fail with 504 `deadline`: for live uses such as a voice call, where a late answer is useless. Every wait counts (the model, retries, the provider rate limit). A decision that misses its deadline is neither stored nor audited; only the miss is counted (project, first model of the plan, deadline and time) as `late` in `GET /v1/summary`. Not with `explain` (422)"
          },
          "images": {
            "type": "array",
            "maxItems": 8,
            "description": "Images judged together with the state, for vision-language models. Each is an `https://` URL (at most 2,048 characters; the provider fetches it) or a `data:image/<png|jpeg|webp|gif>;base64,...` URI (at most 16 MiB decoded; turned upright from its EXIF orientation, stripped of EXIF and scaled to at most 1,568 px on its longest side, and refused over 40 million pixels). Part of the cache key; the audit log keeps only their SHA-256. The model must accept images.",
            "items": {
              "type": "string",
              "examples": [
                "https://example.com/receipt.png",
                "data:image/png;base64,iVBORw0KGgo..."
              ]
            }
          },
          "call": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "^[A-Za-z0-9._:-]+$",
            "description": "An id of your own that ties this decision to the others of one conversation, such as a phone call or a chat session. Kept on the audit entry; `GET /v1/audit?call=<id>` lists that call's decisions. Not part of the cache key"
          },
          "node": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "^[A-Za-z0-9._:-]+$",
            "description": "The name of the place in your app that asks for this decision, such as `checkout.fraud` or `support.triage`. Kept on the audit entry; `GET /v1/audit?node=<name>` lists that node's decisions and `GET /v1/summary` adds them up per node in `by_node`. Not returned in the response and not part of the cache key"
          },
          "assets": {
            "type": "object",
            "maxProperties": 8,
            "description": "Named pictures, recordings and video clips. Every key must be named in `state` or a question (422 otherwise), and each goes to the model as its own part after a `key:` label. At most 8 images and assets together. With audio or video the decision is answered in verbal mode and asked once (no debias); not with `explain`, `mode: logprobs` or `learn`. A video clip (mp4, webm or mov, up to 2 minutes and 40 million pixels a frame; 16 MiB inline, 256 MiB through `file`) goes to Gemini models as a video part and to every other model as up to 16 frames labelled with their time (scene changes plus one frame at least every 2 s) and, where the model hears, its soundtrack; this needs ffmpeg on the server. Box answers on a video carry `at_ms`, the time of the frame they are on. Part of the cache key; the audit log keeps only a salted SHA-256 of each.",
            "propertyNames": {
              "pattern": "^[A-Za-z0-9_-]{1,64}$"
            },
            "additionalProperties": {
              "$ref": "#/components/schemas/Asset"
            }
          },
          "triggers": {
            "type": "object",
            "description": "Actions to fire when the decision's answers hold, by name. Each fired action is listed in the response's `actions` and sent to its destinations beside the decision (never holding it up), logged in GET /v1/deliveries. A trigger with `webhook` needs the project's webhook secret (422 otherwise, before any model call). Only public https addresses are posted to, unless the server's owner lists a host and port in `CURVA_ALLOW_PRIVATE_HOOKS`. Without `triggers`, an ask file's alerts fire",
            "additionalProperties": {
              "$ref": "#/components/schemas/Trigger"
            }
          }
        }
      },
      "Question": {
        "description": "One question. `type` selects the shape.",
        "oneOf": [
          {
            "$ref": "#/components/schemas/ChoiceQuestion"
          },
          {
            "$ref": "#/components/schemas/ScoreQuestion"
          },
          {
            "$ref": "#/components/schemas/NoulQuestion"
          },
          {
            "$ref": "#/components/schemas/MultiQuestion"
          },
          {
            "$ref": "#/components/schemas/TextQuestion"
          },
          {
            "$ref": "#/components/schemas/NumberQuestion"
          },
          {
            "$ref": "#/components/schemas/IntegerQuestion"
          },
          {
            "$ref": "#/components/schemas/BoxQuestion"
          }
        ],
        "discriminator": {
          "propertyName": "type",
          "mapping": {
            "choice": "#/components/schemas/ChoiceQuestion",
            "score": "#/components/schemas/ScoreQuestion",
            "noul": "#/components/schemas/NoulQuestion",
            "multi": "#/components/schemas/MultiQuestion",
            "text": "#/components/schemas/TextQuestion",
            "number": "#/components/schemas/NumberQuestion",
            "integer": "#/components/schemas/IntegerQuestion",
            "box": "#/components/schemas/BoxQuestion"
          }
        }
      },
      "ChoiceQuestion": {
        "type": "object",
        "description": "Pick one option.",
        "required": [
          "type",
          "instructions",
          "options"
        ],
        "properties": {
          "type": {
            "const": "choice"
          },
          "instructions": {
            "type": "string",
            "description": "The question in plain words"
          },
          "options": {
            "type": "object",
            "description": "Key → description (may be `\"\"`), 2–255 options. Over 20 labels the question is answered in verbal mode.",
            "minProperties": 2,
            "maxProperties": 255,
            "additionalProperties": {
              "type": "string"
            }
          },
          "escape": {
            "type": "boolean",
            "default": true,
            "description": "Add a `none_of_these` option so the model is never forced into a wrong pick (the key is reserved)"
          },
          "min_confidence": {
            "$ref": "#/components/schemas/MinConfidence"
          },
          "target_accuracy": {
            "$ref": "#/components/schemas/TargetAccuracy"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          },
          "coverage": {
            "$ref": "#/components/schemas/Coverage"
          }
        }
      },
      "ScoreQuestion": {
        "type": "object",
        "description": "Place on an ordered scale.",
        "required": [
          "type",
          "instructions",
          "levels"
        ],
        "properties": {
          "type": {
            "const": "score"
          },
          "instructions": {
            "type": "string"
          },
          "levels": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 2,
            "maxItems": 20,
            "description": "Level descriptions, lowest first"
          },
          "min_confidence": {
            "$ref": "#/components/schemas/MinConfidence"
          },
          "target_accuracy": {
            "$ref": "#/components/schemas/TargetAccuracy"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          }
        }
      },
      "NoulQuestion": {
        "type": "object",
        "description": "Yes or no, answered as P(yes).",
        "required": [
          "type",
          "instructions"
        ],
        "properties": {
          "type": {
            "const": "noul"
          },
          "instructions": {
            "type": "string"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          },
          "coverage": {
            "$ref": "#/components/schemas/Coverage"
          }
        }
      },
      "MultiQuestion": {
        "type": "object",
        "description": "Pick any subset of the options; each is scored as its own yes/no in the same call.",
        "required": [
          "type",
          "instructions",
          "options"
        ],
        "properties": {
          "type": {
            "const": "multi"
          },
          "instructions": {
            "type": "string"
          },
          "options": {
            "type": "object",
            "minProperties": 1,
            "maxProperties": 20,
            "additionalProperties": {
              "type": "string"
            }
          },
          "threshold": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "default": 0.5,
            "description": "Options with P ≥ threshold are `selected`"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          },
          "coverage": {
            "$ref": "#/components/schemas/Coverage"
          }
        }
      },
      "MinConfidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1,
        "description": "The answer gets `abstain: true` when its confidence is below this. Not together with `target_accuracy` (422)"
      },
      "Coverage": {
        "type": "number",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 1,
        "description": "Choice, multi and noul only (422 elsewhere). Guaranteed accuracy: once the question has 30 feedback labels, the answer gains a split-conformal prediction `set` that contains the true answer with probability ≥ coverage. Not part of the calibration fingerprint or the decision cache key."
      },
      "Promise": {
        "type": "object",
        "description": "Only when the question set `target_accuracy` and a model answered it: why the answer does or does not abstain",
        "required": [
          "target",
          "threshold",
          "labels",
          "accuracy"
        ],
        "properties": {
          "target": {
            "type": "number",
            "description": "The question's `target_accuracy`"
          },
          "threshold": {
            "type": [
              "number",
              "null"
            ],
            "description": "The confidence at or above which answers are acted on (`abstain` is `confidence < threshold`), on the scale of the answer's `confidence`; null while the labels do not prove the target, and then every answer abstains"
          },
          "labels": {
            "type": "integer",
            "description": "Labelled answers of this exact question that were used (the most recent 5,000 at most)"
          },
          "accuracy": {
            "type": [
              "number",
              "null"
            ],
            "description": "Measured accuracy of the labelled answers at or above the threshold; null without a threshold"
          }
        }
      },
      "TargetAccuracy": {
        "type": "number",
        "exclusiveMinimum": 0.5,
        "exclusiveMaximum": 1,
        "description": "Choice, score, text, number and integer only (422 elsewhere), and not together with `min_confidence` (422). Promised accuracy: answers that are not marked `abstain` must be right at least this share of the time. The confidence to act on is learned from this project's feedback for this exact question: the lowest confidence at which at least 30 labelled answers at or above it have a one-sided 95% Wilson lower bound on their accuracy that reaches the target. Until the labels prove one, every answer has `abstain: true`. The answer carries the evidence in `promise`. Not part of the calibration fingerprint or the decision cache key."
      },
      "Label": {
        "description": "A true answer: option key (Choice), level index (Score), `true`/`false` (Noul), list of option keys (Multi), or the value (text, number, integer)",
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "number"
          },
          {
            "type": "boolean"
          },
          {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          {
            "type": "null"
          }
        ]
      },
      "Examples": {
        "type": "array",
        "maxItems": 10,
        "description": "Few-shot examples",
        "items": {
          "type": "object",
          "required": [
            "state",
            "label"
          ],
          "properties": {
            "state": {},
            "label": {
              "$ref": "#/components/schemas/Label"
            }
          }
        }
      },
      "When": {
        "type": "object",
        "description": "`{\"<state field>\": value or [values]}`: ask only when every named top-level field of an object `state` equals its value (or one of the listed values). A field `@<key>` reads question `<key>`'s answer instead (choice: option key; noul: `true` when P(yes) ≥ 0.5; score: most likely level index; multi: list of selected keys; text, number, integer: the value) and makes it a dependency. Otherwise the answer is `{\"skipped\": true}` and no model call is made for it.",
        "additionalProperties": true
      },
      "Rules": {
        "type": "array",
        "maxItems": 32,
        "description": "Tried in order; the first rule whose conditions all hold answers the question without the model. `when` is checked first.",
        "items": {
          "type": "object",
          "required": [
            "if",
            "answer"
          ],
          "properties": {
            "if": {
              "type": "object",
              "description": "Top-level state field (or `@<key>` for another question's answer, as in `when`) → a value (equals), a list (any of) or an operator object: `contains` (case-insensitive), `starts_with`, `gt`, `gte`, `lt`, `lte`, `exists`. Several operators must all hold.",
              "additionalProperties": true
            },
            "answer": {
              "$ref": "#/components/schemas/Label"
            }
          }
        }
      },
      "DependsOn": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Keys of questions answered first, in an earlier stage of the same call. This question sees their answers (and those of their own dependencies) in its prompt, and is skipped when one of them is skipped. `@key` fields in `when` or rule conditions are dependencies too. Unknown keys, self-dependencies, cycles and more than 8 stages get 422."
      },
      "QuestionThink": {
        "type": "boolean",
        "default": false,
        "description": "Answer this question in a verbal call of its own with room to reason, concurrently with its stage's normal call (the request-level `think` makes every question think in one call)."
      },
      "Answer": {
        "type": "object",
        "description": "One question's answer. Only the fields for its question type are set.",
        "properties": {
          "choice": {
            "type": "string",
            "description": "Choice: the chosen option key (may be `none_of_these`)"
          },
          "score": {
            "type": "number",
            "description": "Score: expected level, 0 = lowest"
          },
          "noul": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Noul: P(yes)"
          },
          "selected": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Multi: options at or above the threshold"
          },
          "levels": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Score: the question's levels, lowest first (the legend for `probabilities`); also sent when the questions came from `ask`"
          },
          "probabilities": {
            "description": "Choice and Multi: per option key. Score: per level, lowest first.",
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": {
                  "type": "number"
                }
              },
              {
                "type": "array",
                "items": {
                  "type": "number"
                }
              }
            ]
          },
          "confidence": {
            "type": "number",
            "description": "Choice and Score: probability of the most likely answer. Text, number, integer: P(value is correct)"
          },
          "abstain": {
            "type": "boolean",
            "description": "Only when `min_confidence` or `target_accuracy` was set: true = hand to a human. With `target_accuracy`: true until feedback has proven a threshold, then true below it (see `promise`); false on an answer given by one of the question's `rules`"
          },
          "calibrated": {
            "type": "boolean",
            "description": "A calibrator fitted on this project's feedback adjusted the probabilities"
          },
          "agreement": {
            "type": "number",
            "description": "Council: share of members whose top answer matches the council's"
          },
          "answered_by": {
            "type": "string",
            "description": "Cascade: the model that gave the final answer"
          },
          "unstable": {
            "const": true,
            "description": "Only when the question was asked in both option orders in this request (`debias`) and the two orders gave different most likely answers: another top option or level (choice, score; an exact tie counts as shared), P(yes) on different sides of 0.5 (noul, or any option of a multi), or two values that are not the same answer (text, number, integer). With `min_confidence` or `target_accuracy` the answer then has `abstain: true` whatever its `confidence`. Absent when the orders agree or only one was asked (`debias: false`, `debias: \"auto\"` skipping the reversed order, options keyed `A`, `B`, ..., one order failed, a rule answered). A cached answer keeps it. Council: more than half of the answering members were unstable. Cascade: the flag of the model in `answered_by`"
          },
          "explain": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            },
            "description": "`explain: true`: probability drop without each state field"
          },
          "rule": {
            "type": "integer",
            "description": "Index of the rule that answered (probability 1.0, no model call, not stored for calibration)"
          },
          "stage": {
            "type": "integer",
            "description": "When the request used `depends_on`: the stage (0-based) that answered it"
          },
          "skipped": {
            "const": true,
            "description": "The question's `when` failed, or a question it depends on was skipped: no answer"
          },
          "value": {
            "type": [
              "string",
              "number",
              "integer",
              "null"
            ],
            "description": "Text, number or integer: the extracted value (`null` when the state has none, or the reply had no valid value, which comes with confidence 0)"
          },
          "coverage": {
            "type": "number",
            "description": "Only when the question set `coverage`: echoed"
          },
          "guaranteed": {
            "type": "boolean",
            "description": "Only when the question set `coverage`: true once 30 labels back the guarantee (then `set` is present); false before, with no `set`"
          },
          "set": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Only when `guaranteed`: option keys (choice, multi) or `\"true\"`/`\"false\"` (noul) containing the true answer with probability ≥ `coverage`. One key = a confident answer; several = show the options or route to a human. Multi reports `guaranteed: false` until its options can be labeled one by one"
          },
          "promise": {
            "$ref": "#/components/schemas/Promise"
          },
          "type": {
            "type": "string",
            "description": "Box: `box`"
          },
          "found": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Box: P(the thing is there): `confidence` when a box came back, else 1 - `confidence`"
          },
          "box": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Edges"
              },
              {
                "type": "null"
              }
            ],
            "description": "Box: the first box, or null when it is not there"
          },
          "boxes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Edges"
            },
            "description": "Box: every box, up to `max_boxes`"
          },
          "evidence": {
            "type": "array",
            "description": "With `sources`: the passages this answer rests on. Empty means the library did not answer it, and the answer is marked `abstain`",
            "items": {
              "type": "object",
              "properties": {
                "file": {"type": "string"},
                "name": {"type": "string"},
                "page": {"type": ["integer", "null"], "description": "null for a picture"},
                "bbox": {"type": ["array", "null"], "items": {"type": "number"}},
                "snippet": {"type": "string"}
              }
            }
          }
        }
      },
      "DecideResponse": {
        "type": "object",
        "required": [
          "id",
          "model",
          "project",
          "config",
          "mode",
          "latency_ms",
          "wall_ms",
          "cost_usd",
          "cached",
          "debiased",
          "answers"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "`dec_…`: unique and sortable by time"
          },
          "model": {
            "type": "string"
          },
          "project": {
            "type": "string"
          },
          "config": {
            "type": "string",
            "description": "The pinned config the decision ran under"
          },
          "mode": {
            "type": "string",
            "enum": [
              "logprobs",
              "verbal"
            ],
            "description": "The mode that actually answered"
          },
          "latency_ms": {
            "type": "integer",
            "description": "Model time only: the time of the model calls that gave the answers (calls in the same stage run concurrently, stages one after another). It leaves out the wait for Curva's own rate limit, earlier attempts that were retried and the backoff between them, models that failed before another one answered, the one logprobs attempt on a model that turns out to have no logprobs, and Curva's own work. `wall_ms` has all of it"
          },
          "wall_ms": {
            "type": "integer",
            "description": "The whole time the decision took, from when Curva started on the request until the answer was ready to send: rate-limit waits, retries, every model call, calibration and storing the decision. At least `latency_ms`; small for a cached decision"
          },
          "cost_usd": {
            "type": "number",
            "description": "Summed over every model call"
          },
          "cached": {
            "type": "boolean",
            "description": "Served from the decision cache: no model call (true only when every call was)"
          },
          "debiased": {
            "type": "boolean",
            "description": "Asked in both option orders and averaged"
          },
          "lessons": {
            "type": "integer",
            "description": "Only on a request sent with `learn`: how many examples from your feedback were shown to the model"
          },
          "learned_us": {
            "type": "integer",
            "description": "Only when Curva answered a question by itself (`learned`): microseconds it took"
          },
          "answers": {
            "type": "object",
            "description": "Question key → answer, in request order",
            "additionalProperties": {
              "$ref": "#/components/schemas/Answer"
            }
          },
          "receipt": {
            "type": "object",
            "description": "Ed25519 signature over `signed`, verifiable offline with the keys of GET /v1/receipts/keys (`curva receipt verify`, Python `verify_receipt`, TypeScript `verifyReceipt`)",
            "required": [
              "signed",
              "sig"
            ],
            "properties": {
              "signed": {
                "type": "string",
                "description": "JSON text of what is signed: v (2; receipts made before had 1), key, id, at (unix ms), project, model, mode (as in the response: also `fallback` or `local`), by (per answered question, what gave it: `model`, `cache`, `rule`, `learned`, `local` or `fallback`; version 2 only), state (the audit log's salted state hash), answers (each answer without explain, evidence or other extras) and chain (the decision's audit chain link)"
              },
              "sig": {
                "type": "string",
                "description": "Ed25519 signature of the UTF-8 bytes of `signed`, in hex"
              }
            }
          },
          "actions": {
            "type": "array",
            "description": "The triggers that fired, present only when one did. Each is sent to its destinations after the response; see GET /v1/deliveries for the outcome",
            "items": {
              "type": "object",
              "required": [
                "name",
                "id",
                "because"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "The trigger's name"
                },
                "id": {
                  "type": "string",
                  "description": "`act_...`; the `x-curva-idempotency-key` of every delivery and replay of this action"
                },
                "because": {
                  "type": "object",
                  "description": "The answers that made it fire, and `p`, their least confidence"
                }
              }
            }
          }
        }
      },
      "CompatRequest": {
        "type": "object",
        "required": [
          "state",
          "questions"
        ],
        "description": "Any `/v1/decide` field is accepted too (`project`, `debias`, `privacy`, ...).",
        "properties": {
          "state": {},
          "model": {
            "description": "`curva-x.y.z` / `curva-latest` selects a config; a name without a provider prefix means the server default; else as in `/v1/decide`"
          },
          "questions": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "choice",
                    "score",
                    "noul",
                    "multi",
                    "text",
                    "number",
                    "integer",
                    "box"
                  ]
                },
                "instructions": {
                  "description": "Text or JSON; may be omitted"
                },
                "criteria": {
                  "description": "Choice: key → description (text, null or JSON). Score: level descriptions, lowest first. Noul: `{\"true\": ..., \"false\": ...}`"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      },
      "CompatResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/DecideResponse"
          }
        ],
        "type": "object",
        "properties": {
          "answers": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "description": "As `Answer`, plus `type`; a Score's `probabilities` and `legend` are keyed by level (`\"0\"`, `\"1\"`, ...)",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "choice",
                    "score",
                    "noul",
                    "multi",
                    "text",
                    "number",
                    "integer",
                    "box"
                  ]
                },
                "legend": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "required": [
              "input_tokens",
              "output_tokens"
            ],
            "properties": {
              "input_tokens": {
                "type": "integer"
              },
              "output_tokens": {
                "type": "integer",
                "description": "Not tracked; always 0"
              }
            }
          }
        }
      },
      "FeedbackRequest": {
        "type": "object",
        "description": "Send `decision_id` for one decision, or `call` (and `project`) to label every decision of a listened call that answered `question`; the response then has `call`, `project` and `decisions` (how many were labelled) instead of `decision_id`. Fallbacks are not labelled.",
        "required": [
          "question",
          "label"
        ],
        "properties": {
          "decision_id": {
            "type": "string"
          },
          "call": {
            "type": "string",
            "description": "A call id: labels every decision of that call"
          },
          "project": {
            "type": "string",
            "description": "With `call` only (default `default`)"
          },
          "question": {
            "type": "string"
          },
          "label": {
            "$ref": "#/components/schemas/Label"
          }
        }
      },
      "FeedbackResponse": {
        "type": "object",
        "required": [
          "decision_id",
          "question",
          "labels",
          "min_labels",
          "calibrated"
        ],
        "properties": {
          "decision_id": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "labels": {
            "type": "integer",
            "description": "Labels now recorded for this exact question in this project"
          },
          "min_labels": {
            "type": "integer",
            "description": "Labels needed before answers are calibrated"
          },
          "calibrated": {
            "type": "boolean"
          }
        }
      },
      "QualityReport": {
        "type": "object",
        "required": [
          "accuracy",
          "ece",
          "brier",
          "automated",
          "accuracy_when_automated",
          "reliability"
        ],
        "properties": {
          "accuracy": {
            "type": "number"
          },
          "ece": {
            "type": "number",
            "description": "Expected calibration error"
          },
          "brier": {
            "type": "number"
          },
          "automated": {
            "type": "number",
            "description": "Share of answers at ≥ 0.9 confidence"
          },
          "accuracy_when_automated": {
            "type": "number"
          },
          "reliability": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "count",
                "confidence",
                "accuracy"
              ],
              "properties": {
                "count": {
                  "type": "integer"
                },
                "confidence": {
                  "type": "number"
                },
                "accuracy": {
                  "type": "number"
                }
              }
            }
          }
        }
      },
      "CalibrationResponse": {
        "type": "object",
        "required": [
          "project",
          "question",
          "fingerprint",
          "model",
          "labels",
          "min_labels",
          "calibrator",
          "before",
          "after"
        ],
        "properties": {
          "project": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "fingerprint": {
            "type": "string",
            "description": "Hash of the question's type, wording and options"
          },
          "model": {
            "type": "string",
            "description": "The model this report covers: `labels`, `calibrator`, `before` and `after` count only its answers"
          },
          "labels": {
            "type": "integer"
          },
          "min_labels": {
            "type": "integer"
          },
          "calibrator": {
            "description": "Applied to new answers from `model` only; null until `min_labels` of its answers are labelled",
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "required": [
                  "kind",
                  "t"
                ],
                "properties": {
                  "kind": {
                    "const": "temperature"
                  },
                  "t": {
                    "type": "number"
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "kind",
                  "a",
                  "b"
                ],
                "properties": {
                  "kind": {
                    "const": "platt"
                  },
                  "a": {
                    "type": "number"
                  },
                  "b": {
                    "type": "number"
                  }
                }
              }
            ]
          },
          "before": {
            "description": "Raw probabilities against the labels",
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/QualityReport"
              }
            ]
          },
          "after": {
            "description": "Held out: each half calibrated by a fit on the other half",
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/QualityReport"
              }
            ]
          },
          "promise": {
            "$ref": "#/components/schemas/PromiseReport",
            "description": "Only with `target`: the threshold a question with that `target_accuracy` is decided by right now, and the evidence behind it"
          }
        }
      },
      "PromiseReport": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Promise"
          },
          {
            "type": "object",
            "required": [
              "automated",
              "lower_bound"
            ],
            "properties": {
              "automated": {
                "type": "number",
                "description": "Share of the labelled answers at or above the threshold (0 without one)"
              },
              "lower_bound": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "One-sided 95% Wilson lower bound of `accuracy`; at least `target` when there is a threshold, null without one"
              }
            }
          }
        ]
      },
      "AuditEntry": {
        "type": "object",
        "required": [
          "id",
          "project",
          "api_key",
          "state_hash",
          "model",
          "mode",
          "config",
          "privacy",
          "answers",
          "latency_ms",
          "cost_usd",
          "cached",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "project": {
            "type": "string"
          },
          "api_key": {
            "type": [
              "string",
              "null"
            ],
            "description": "The key id (never the key)"
          },
          "state_hash": {
            "type": "string",
            "description": "SHA-256 of the state"
          },
          "model": {
            "type": "string"
          },
          "mode": {
            "type": "string"
          },
          "config": {
            "type": "string"
          },
          "privacy": {
            "type": "string",
            "enum": [
              "standard",
              "strict"
            ]
          },
          "answers": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Answer"
            }
          },
          "latency_ms": {
            "type": "integer",
            "description": "Model time only, as in the decide response"
          },
          "cost_usd": {
            "type": "number"
          },
          "cached": {
            "type": "boolean"
          },
          "created_at": {
            "type": "integer",
            "description": "Unix ms"
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "SHA-256 of each image as sent; only when the decision had images (images are never stored)"
          },
          "deadline_ms": {
            "type": "integer",
            "description": "The request's `deadline_ms`; only on decisions that had one"
          },
          "call": {
            "type": "string",
            "description": "The request's `call` id; only on decisions that had one"
          },
          "node": {
            "type": "string",
            "description": "The request's `node` name; only on decisions that had one"
          },
          "wall_ms": {
            "type": "integer",
            "description": "The whole time the decision took, as in the decide response; absent on decisions recorded before it was"
          },
          "actions": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "The actions a listened decision fired (`name`, `id`, `because`); only on decisions that fired some"
          }
        }
      },
      "WatchStart": {
        "type": "object",
        "required": [
          "type"
        ],
        "additionalProperties": false,
        "properties": {
          "type": {
            "const": "start"
          },
          "key": {
            "type": "string",
            "description": "The Curva API key, when it is not in the `Authorization` header"
          },
          "stream": {
            "type": "string",
            "description": "The stream id (1–64 characters); made up when absent. Decisions are logged under it as their `call`"
          },
          "project": {
            "type": "string"
          },
          "node": {
            "type": "string"
          },
          "ask": {
            "type": "string",
            "description": "A ready-made set: `driving` (experimental), or any call set; or the text of an ask file, whose alerts become the triggers (see /v1/ask-file)"
          },
          "questions": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Question"
            },
            "description": "Your own questions: noul, choice, score, box, text, number, integer"
          },
          "fps": {
            "type": "number",
            "description": "Frames per second looked at (default 10, at most 30); faster frames are dropped"
          },
          "max_quiet_s": {
            "type": "number",
            "description": "A frame goes to the model at least this often even when nothing changes (default 10, 1 to 3600)"
          },
          "deadline_ms": {
            "type": "integer"
          },
          "fallback": {
            "type": "object",
            "description": "One answer per question, used when the deadline is missed"
          },
          "triggers": {
            "type": "object",
            "maxProperties": 16,
            "additionalProperties": {
              "$ref": "#/components/schemas/Trigger"
            }
          },
          "on": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "state": {
            "type": "object",
            "description": "Readings merged into every frame's state (at most 16 KiB), so rules and triggers can use them"
          },
          "model": {
            "type": "string",
            "description": "A vision-capable model; the server's default model otherwise"
          },
          "speculative": {
            "type": "boolean",
            "description": "Act on the local model's first frame where a trigger holds at once, marked `confirmed: false`, and let the hosted model confirm or retract it in the background (default true); false waits for the trigger's `confirm` (k of the last n judged frames) or one frame at `min_p_single`"
          }
        }
      },
      "WatchEvent": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "decision",
              "action",
              "confirmed",
              "retracted",
              "receipt",
              "error"
            ]
          },
          "frame": {
            "type": "integer"
          },
          "at_ms": {
            "type": "integer",
            "description": "Milliseconds since the stream started"
          },
          "tier": {
            "type": "string",
            "enum": [
              "gate",
              "local",
              "cache",
              "model"
            ],
            "description": "Who answered: the change gate (the last answers repeated), the local model (milliseconds), the hosted model's answer to a near-identical frame of this stream in the last 30 s, or the hosted vision model"
          },
          "confirmed": {
            "type": ["boolean", "integer"],
            "description": "On an action fired speculatively from the local model's answer: false until the hosted model confirms or retracts it. On the receipt: an integer, the speculative actions confirmed"
          },
          "action": {
            "type": "string",
            "description": "On `confirmed` and `retracted`: the id of the action checked"
          },
          "by_frame": {
            "type": "integer",
            "description": "On `confirmed` and `retracted`: the frame the hosted model judged"
          },
          "after_ms": {
            "type": "integer",
            "description": "On `confirmed` and `retracted`: milliseconds from the action's frame arriving to the check"
          },
          "fired": {
            "type": "integer",
            "description": "On the receipt: actions fired in the whole stream"
          },
          "retracted": {
            "type": "integer",
            "description": "On the receipt: speculative actions the hosted model retracted (the receipt's `confirmed` counts those it confirmed)"
          },
          "median_check_ms": {
            "type": "integer",
            "description": "On the receipt: median `after_ms` of the last 1,000 checks"
          },
          "local": {
            "type": "integer",
            "description": "On the receipt: frames answered by the local model and not sent to the hosted model (the hosted-model calls saved)"
          },
          "cached": {
            "type": "integer",
            "description": "On the receipt: frames answered with the hosted model's answer to a near-identical earlier frame of this stream (`tier: cache`), not sent to the hosted model"
          },
          "reused": {
            "type": "integer",
            "description": "On the receipt: decisions that reused an earlier hosted-model answer, including those whose speculative action was then sent to the hosted model to confirm"
          },
          "cropped": {
            "type": "integer",
            "description": "On the receipt: frames sent to the hosted model as only their changed area (servers with CURVA_WATCH_CROPS=on)"
          },
          "audits": {
            "type": "integer",
            "description": "On the receipt, when the server has the local model: frames the camera's heads answered alone that were also sent to the hosted model as a check (about one in 20)"
          },
          "heads": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "enum": ["learning", "shadowing", "on"]
            },
            "description": "On the receipt, when the server has the local model: the stage of this camera's head for each yes/no question. Only `on` answers frames alone"
          },
          "local_latency_ms": {
            "type": "object",
            "properties": {
              "p50": {"type": "number"},
              "p99": {"type": "number"}
            },
            "description": "On the receipt: time from a frame's arrival to its local decision, over the last 1,000 local decisions"
          },
          "checked": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "On the receipt: every `confirmed` and `retracted` event"
          },
          "unconfirmed": {
            "type": "integer",
            "description": "On the receipt: actions fired from the local model that the hosted model never checked"
          },
          "id": {
            "type": "string"
          },
          "answers": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Answer"
            }
          },
          "latency_ms": {
            "type": "integer"
          },
          "fallback": {
            "type": "boolean"
          },
          "rate_limited": {
            "type": "boolean"
          },
          "receipt": {
            "type": "object",
            "description": "The signed receipt of a model decision, as on `/v1/decide`",
            "properties": {
              "signed": {
                "type": "string"
              },
              "sig": {
                "type": "string"
              }
            }
          },
          "name": {
            "type": "string"
          },
          "because": {
            "type": "object"
          },
          "decision": {
            "type": "string"
          },
          "stream": {
            "type": "string"
          },
          "frames": {
            "type": "integer"
          },
          "gated": {
            "type": "integer"
          },
          "sent_to_model": {
            "type": "integer"
          },
          "dropped": {
            "type": "integer"
          },
          "refused": {
            "type": "integer"
          },
          "error": {
            "type": "object"
          }
        }
      },
      "ListenStart": {
        "type": "object",
        "required": [
          "type"
        ],
        "additionalProperties": false,
        "properties": {
          "type": {
            "const": "start"
          },
          "key": {
            "type": "string",
            "description": "The Curva API key, when it is not in the `Authorization` header"
          },
          "call": {
            "type": "string",
            "description": "The call id (1–64 characters); made up when absent"
          },
          "project": {
            "type": "string"
          },
          "node": {
            "type": "string"
          },
          "sample_rate": {
            "type": "integer",
            "enum": [
              16000,
              8000
            ],
            "default": 16000,
            "description": "8000 for `mulaw`"
          },
          "encoding": {
            "type": "string",
            "enum": [
              "pcm16",
              "mulaw"
            ],
            "default": "pcm16"
          },
          "ask": {
            "description": "A built-in set (`scam`, `hear`, ...), as in `/v1/decide`"
          },
          "questions": {
            "type": "object",
            "description": "Choice, score and noul questions; send `ask` or `questions`"
          },
          "deadline_ms": {
            "type": "integer",
            "description": "Longest wait from the end of an utterance to its answer; needs `fallback`"
          },
          "fallback": {
            "type": "object",
            "description": "The answer to every question when no answer comes in time (a choice's key, a noul's true or false, a score's level)"
          },
          "triggers": {
            "type": "object",
            "maxProperties": 16,
            "additionalProperties": {
              "$ref": "#/components/schemas/Trigger"
            }
          },
          "model": {
            "type": "string",
            "description": "The upstream live model (default `gemini-3.1-flash-live-preview`)"
          }
        }
      },
      "Trigger": {
        "type": "object",
        "required": [
          "if"
        ],
        "additionalProperties": false,
        "properties": {
          "if": {
            "$ref": "#/components/schemas/When",
            "description": "Rule conditions on choice and noul answers, such as `{\"@verdict\": \"block\"}` or `{\"@caller_state\": [\"distressed\", \"emergency\"]}`"
          },
          "min_p": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "default": 0,
            "description": "Lowest calibrated confidence of the matched answers"
          },
          "confirm": {
            "type": "object",
            "required": ["k", "n"],
            "additionalProperties": false,
            "properties": {"k": {"type": "integer", "minimum": 1}, "n": {"type": "integer", "maximum": 30}},
            "description": "Only on `/v1/watch` (default `{\"k\": 2, \"n\": 3}`): fire when the trigger holds on k of the last n judged frames; frames the gate drops are no new evidence. It fires again only after it held on none of the last n"
          },
          "min_p_single": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Only on `/v1/watch` (default 0.95): fire on one judged frame at this confidence or above, without waiting for k of n"
          },
          "webhook": {
            "type": "string",
            "format": "uri",
            "description": "An https URL on a public address, POSTed the action signed with the project's webhook secret (`curva keys webhook-secret <project>`)"
          },
          "slack": {
            "type": "string",
            "format": "uri",
            "description": "A Slack incoming-webhook URL (`https://hooks.slack.com/services/...`), posted one readable line as `{\"text\": ...}`"
          },
          "teams": {
            "type": "string",
            "format": "uri",
            "description": "A Microsoft Teams Workflows or incoming-webhook URL, posted an Adaptive Card with the same line"
          },
          "discord": {
            "type": "string",
            "format": "uri",
            "description": "A Discord channel webhook URL, posted `{\"content\": ...}` with mentions off"
          },
          "telegram": {
            "type": "string",
            "format": "uri",
            "description": "`https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat id>`, posted `{\"chat_id\": ..., \"text\": ...}`; a URL without `chat_id` is refused"
          },
          "timeout_ms": {
            "type": "integer",
            "minimum": 1,
            "maximum": 30000,
            "default": 5000,
            "description": "How long to wait for each destination on each attempt. A delivery is tried up to 3 times when the receiver is down, times out or answers 408, 429 or 5xx"
          },
          "repeat": {
            "type": "boolean",
            "default": false,
            "description": "Only on `/v1/listen` and `/v1/watch`: fire every time the trigger holds, not once per event"
          },
          "on_fallback": {
            "type": "boolean",
            "default": false,
            "description": "Also fire on a fallback answer (the model missed `deadline_ms`)"
          }
        }
      },
      "ListenEvent": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "decision",
              "action",
              "receipt",
              "error"
            ]
          },
          "utterance": {
            "type": "integer"
          },
          "id": {
            "type": "string",
            "description": "`dec_…` for a decision, `act_…` for an action"
          },
          "answers": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Answer"
            }
          },
          "latency_ms": {
            "type": "integer",
            "description": "From the end of the utterance to the answer"
          },
          "forced": {
            "type": "boolean",
            "description": "The utterance was cut while the caller kept talking"
          },
          "fallback": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          },
          "because": {
            "type": "object",
            "description": "The matched answers and `p`, their lowest confidence"
          },
          "decision": {
            "type": "string"
          },
          "error": {
            "type": "object"
          }
        }
      },
      "AuditResponse": {
        "type": "object",
        "required": [
          "project",
          "entries",
          "next_before"
        ],
        "properties": {
          "project": {
            "type": "string"
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AuditEntry"
            }
          },
          "next_before": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pass as `before` for the next page; null on the last page"
          }
        }
      },
      "DriftResponse": {
        "type": "object",
        "required": [
          "project",
          "question",
          "weeks"
        ],
        "properties": {
          "project": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "weeks": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "week",
                "decisions",
                "mix",
                "confidence"
              ],
              "properties": {
                "week": {
                  "type": "string",
                  "examples": [
                    "2026-W39"
                  ]
                },
                "decisions": {
                  "type": "integer"
                },
                "mix": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "number"
                  },
                  "description": "Share of decisions per top label (raw probabilities)"
                },
                "confidence": {
                  "type": "number",
                  "description": "Average probability of the top label (raw)"
                },
                "mix_change": {
                  "type": "number",
                  "description": "Latest week only: total-variation distance from the previous weeks' average mix"
                },
                "confidence_change": {
                  "type": "number"
                },
                "drift": {
                  "type": "boolean",
                  "description": "`mix_change` > 0.2 or |`confidence_change`| > 0.1"
                }
              }
            }
          }
        }
      },
      "ModelsResponse": {
        "type": "object",
        "required": [
          "models",
          "default_model"
        ],
        "properties": {
          "default_model": {
            "type": "object",
            "required": [
              "model",
              "previous",
              "changed_at"
            ],
            "properties": {
              "model": {
                "type": "string",
                "description": "The model a request without `model` uses"
              },
              "previous": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The default model before the last change, seen at a start; calibration fitted on its answers is not applied to the new default's. Null until the default first changes"
              },
              "changed_at": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "When the server started with the new default, in Unix milliseconds"
              }
            }
          },
          "models": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "description",
                "release_date"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "release_date": {
                  "type": "string",
                  "description": "Not recorded; always empty"
                }
              }
            }
          }
        }
      },
      "TextQuestion": {
        "type": "object",
        "description": "Extract a short text value. Answered with a value the model writes, so always verbal mode (`mode: logprobs` gets 422).",
        "required": [
          "type",
          "instructions"
        ],
        "properties": {
          "type": {
            "const": "text"
          },
          "instructions": {
            "type": "string"
          },
          "max_length": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2000,
            "default": 200,
            "description": "Most characters in the value"
          },
          "nullable": {
            "type": "boolean",
            "default": false,
            "description": "The answer may be `null` when the state has no such value"
          },
          "min_confidence": {
            "$ref": "#/components/schemas/MinConfidence"
          },
          "target_accuracy": {
            "$ref": "#/components/schemas/TargetAccuracy"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          }
        }
      },
      "NumberQuestion": {
        "type": "object",
        "description": "Extract a number. Answered with a value the model writes, so always verbal mode (`mode: logprobs` gets 422).",
        "required": [
          "type",
          "instructions"
        ],
        "properties": {
          "type": {
            "const": "number"
          },
          "instructions": {
            "type": "string"
          },
          "min": {
            "type": "number",
            "description": "Inclusive lower bound"
          },
          "max": {
            "type": "number",
            "description": "Inclusive upper bound"
          },
          "nullable": {
            "type": "boolean",
            "default": false,
            "description": "The answer may be `null` when the state has no such value"
          },
          "min_confidence": {
            "$ref": "#/components/schemas/MinConfidence"
          },
          "target_accuracy": {
            "$ref": "#/components/schemas/TargetAccuracy"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          }
        }
      },
      "IntegerQuestion": {
        "type": "object",
        "description": "Extract a whole number. Answered with a value the model writes, so always verbal mode (`mode: logprobs` gets 422).",
        "required": [
          "type",
          "instructions"
        ],
        "properties": {
          "type": {
            "const": "integer"
          },
          "instructions": {
            "type": "string"
          },
          "min": {
            "type": "number",
            "description": "Inclusive lower bound"
          },
          "max": {
            "type": "number",
            "description": "Inclusive upper bound"
          },
          "nullable": {
            "type": "boolean",
            "default": false,
            "description": "The answer may be `null` when the state has no such value"
          },
          "min_confidence": {
            "$ref": "#/components/schemas/MinConfidence"
          },
          "target_accuracy": {
            "$ref": "#/components/schemas/TargetAccuracy"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          }
        }
      },
      "Asset": {
        "type": "object",
        "description": "One picture, recording or video clip. Give exactly one of `data_base64`, `url`, `part` or (video only) `file`.",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "image",
              "audio",
              "video"
            ]
          },
          "format": {
            "type": "string",
            "enum": [
              "png",
              "jpeg",
              "webp",
              "gif",
              "wav",
              "mp3",
              "pcm16",
              "mulaw",
              "mp4",
              "webm",
              "mov"
            ],
            "description": "Images: png, jpeg, webp, gif (optional with an image `url`). Audio: wav, mp3, pcm16 (raw 16-bit mono, needs `sample_rate`) or mulaw (8 kHz unless `sample_rate`); pcm16 and mulaw are turned into wav. Video: mp4, webm or mov (optional: read from the file itself)"
          },
          "data_base64": {
            "type": "string",
            "description": "The file, base64. Images and video at most 16 MiB, audio at most 10 MiB; audio and video at most 2 minutes"
          },
          "url": {
            "type": "string",
            "description": "An https URL. An image URL goes to the model provider as is; an audio or video URL is fetched by Curva, over https from a public address only"
          },
          "part": {
            "type": "string",
            "description": "The name of a part of a `multipart/form-data` request holding the file"
          },
          "file": {
            "type": "string",
            "description": "Video only: the id of a file uploaded with POST /v1/files (`file_...`), for clips over 16 MiB (up to 256 MiB)"
          },
          "sample_rate": {
            "type": "integer",
            "minimum": 8000,
            "maximum": 48000,
            "description": "pcm16 and mulaw only"
          }
        }
      },
      "BoxQuestion": {
        "type": "object",
        "description": "Where something is in the pictures: the answer is up to `max_boxes` boxes, or null when it is not there. Answered with a value the model writes, so always verbal mode (`mode: logprobs` gets 422).",
        "required": [
          "type",
          "instructions"
        ],
        "properties": {
          "type": {
            "const": "box"
          },
          "instructions": {
            "type": "string"
          },
          "max_boxes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "default": 1
          },
          "min_confidence": {
            "$ref": "#/components/schemas/MinConfidence"
          },
          "target_accuracy": {
            "$ref": "#/components/schemas/TargetAccuracy"
          },
          "examples": {
            "$ref": "#/components/schemas/Examples"
          },
          "when": {
            "$ref": "#/components/schemas/When"
          },
          "rules": {
            "$ref": "#/components/schemas/Rules"
          },
          "depends_on": {
            "$ref": "#/components/schemas/DependsOn"
          },
          "think": {
            "$ref": "#/components/schemas/QuestionThink"
          }
        }
      },
      "Edges": {
        "type": "object",
        "description": "Edges as fractions of the picture from its top-left corner: top and bottom of its height, left and right of its width",
        "required": [
          "top",
          "left",
          "bottom",
          "right"
        ],
        "properties": {
          "top": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "left": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "bottom": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "right": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          }
        }
      }
    }
  }
}
