{
  "components": {
    "schemas": {
      "Error": {
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      }
    },
    "securitySchemes": {
      "workspaceBearer": {
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "info": {
    "title": "HumanBracket Decision API",
    "version": "1.0.0"
  },
  "openapi": "3.0.3",
  "paths": {
    "/v1/decisions/{decision_id}/corrections": {
      "post": {
        "operationId": "correctDecision",
        "parameters": [
          {
            "in": "path",
            "name": "decision_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "additionalProperties": false,
                "properties": {
                  "output": {
                    "additionalProperties": false,
                    "properties": {
                      "choice": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "choice"
                    ],
                    "type": "object"
                  },
                  "reason": {
                    "maxLength": 500,
                    "type": "string"
                  }
                },
                "required": [
                  "output",
                  "reason"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "decision_id": {
                      "format": "uuid",
                      "type": "string"
                    },
                    "decision_revision": {
                      "minimum": 1,
                      "type": "integer"
                    },
                    "output": {
                      "properties": {
                        "choice": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "choice"
                      ],
                      "type": "object"
                    }
                  },
                  "required": [
                    "decision_id",
                    "decision_revision",
                    "output"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Successful response"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Invalid correction."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Missing, invalid or revoked workspace key."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "The key lacks correction scope."
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Decision unavailable in this workspace."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "The decision revision was invalidated."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Decision or policy schema unavailable."
          }
        },
        "summary": "Append a corrected outcome"
      }
    },
    "/v1/models/{slug}/execute": {
      "post": {
        "operationId": "executeDecision",
        "parameters": [
          {
            "in": "path",
            "name": "slug",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Replays the same successful request for 24 hours.",
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "pattern": "^[!-~]+$",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "additionalProperties": false,
                "properties": {
                  "inputs": {
                    "type": "object"
                  },
                  "reference_id": {
                    "maxLength": 256,
                    "type": "string"
                  }
                },
                "required": [
                  "inputs"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "cached": {
                      "type": "boolean"
                    },
                    "decision_id": {
                      "format": "uuid",
                      "type": "string"
                    },
                    "decision_revision": {
                      "minimum": 1,
                      "type": "integer"
                    },
                    "execution_id": {
                      "format": "uuid",
                      "type": "string"
                    },
                    "model": {
                      "pattern": "^[-a-zA-Z0-9_]+$",
                      "type": "string"
                    },
                    "output": {
                      "properties": {
                        "choice": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "choice"
                      ],
                      "type": "object"
                    },
                    "policy_version": {
                      "minimum": 1,
                      "type": "integer"
                    },
                    "processing_time_ms": {
                      "minimum": 0,
                      "type": "integer"
                    },
                    "reference_id": {
                      "nullable": true,
                      "type": "string"
                    },
                    "source": {
                      "enum": [
                        "ai",
                        "memory"
                      ],
                      "type": "string"
                    },
                    "status": {
                      "enum": [
                        "completed",
                        "provisional"
                      ],
                      "type": "string"
                    }
                  },
                  "required": [
                    "execution_id",
                    "decision_id",
                    "decision_revision",
                    "reference_id",
                    "model",
                    "policy_version",
                    "status",
                    "output",
                    "source",
                    "cached",
                    "processing_time_ms"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Successful response"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Invalid input or idempotency key."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Missing, invalid or revoked workspace key."
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Published model unavailable in this workspace."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Idempotency key was used with a different request."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Decision unavailable or a matching request is in progress.",
            "headers": {
              "Retry-After": {
                "description": "Present for decision_busy.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "summary": "Execute a published model"
      }
    }
  },
  "security": [
    {
      "workspaceBearer": []
    }
  ]
}
