{
  "openapi": "3.1.0",
  "info": {
    "title": "AI Detector API",
    "version": "1.1.0",
    "description": "AI authorship estimates using Jev. 50–5,000 words per request. Scores are estimates, not proof."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/api/v1/detect": {
      "post": {
        "summary": "Classify text",
        "operationId": "detectText",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[\\w.-]{8,128}$"
            },
            "description": "Retry with the same key and text for up to 30 days without another check."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "additionalProperties": false,
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 50000,
                    "description": "50–5,000 whitespace-delimited words."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Detection result",
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "X-Detector-Mode": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "live",
                    "reference"
                  ]
                }
              },
              "X-Idempotent-Replay": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "true",
                    "false"
                  ]
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Detection"
                }
              }
            }
          },
          "400": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Structured error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "aid_live_…"
      }
    },
    "schemas": {
      "Detection": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "label",
          "probabilities",
          "cost_usd"
        ],
        "properties": {
          "label": {
            "type": "string",
            "enum": [
              "ai",
              "human"
            ]
          },
          "probabilities": {
            "type": "object",
            "required": [
              "ai",
              "human"
            ],
            "additionalProperties": false,
            "properties": {
              "ai": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "human": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              }
            }
          },
          "cost_usd": {
            "type": "number",
            "minimum": 0,
            "description": "Original check charge in USD. An idempotent replay does not charge again."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
