{
  "openapi": "3.1.0",
  "info": {
    "title": "Unslop API",
    "version": "0.1.0",
    "description": "API reference for rewriting, detection, writing styles and preservation reports."
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/rewrites": {
      "post": {
        "summary": "Create rewrite job",
        "operationId": "post_v1_rewrites",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewriteJob"
                }
              }
            }
          },
          "202": {
            "description": "Job queued or running; poll GET /v1/rewrites/{id}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewriteJob"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient prepaid credits or included MCP allowance. No inference starts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 160
            }
          },
          {
            "name": "X-gptzero-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-zerogpt-Key",
            "in": "header",
            "description": "Provider bearer access token",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-sapling-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-winston-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-pangram-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-copyleaks-Key",
            "in": "header",
            "description": "Provider bearer access token",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RewriteRequest"
              },
              "example": {
                "text": "The field trial involved 48 volunteers over a period of six weeks. Participants recorded their sleep duration each morning and completed a short attention test in the afternoon.\n\nThe results suggest that consistent sleep schedules were associated with improved attention. However, the study did not establish that changing sleep habits caused the improvement.\n\nFurther research is needed to determine whether the findings apply to people who work night shifts. The small sample size also limits the conclusions that can be drawn from this study.",
                "alternatives": 1,
                "wait": true
              }
            }
          }
        }
      },
      "get": {
        "summary": "List rewrite jobs",
        "operationId": "get_v1_rewrites",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rewrites/{id}": {
      "get": {
        "summary": "Get rewrite job",
        "operationId": "get_v1_rewrites__id_",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewriteJob"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/rewrites/{id}/rerun": {
      "post": {
        "summary": "Create another revision",
        "operationId": "post_v1_rewrites__id__rerun",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewriteJob"
                }
              }
            }
          },
          "202": {
            "description": "Job queued or running; poll GET /v1/rewrites/{id}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewriteJob"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient prepaid credits or included MCP allowance. No inference starts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 160
            }
          },
          {
            "name": "X-gptzero-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-zerogpt-Key",
            "in": "header",
            "description": "Provider bearer access token",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-sapling-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-winston-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-pangram-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-copyleaks-Key",
            "in": "header",
            "description": "Provider bearer access token",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "writing_style": {
                    "type": "string",
                    "enum": [
                      "default",
                      "academic",
                      "plain",
                      "formal",
                      "casual",
                      "concise"
                    ],
                    "default": "default"
                  },
                  "strength": {
                    "type": "string",
                    "enum": [
                      "light",
                      "balanced",
                      "strong"
                    ],
                    "default": "balanced"
                  },
                  "rank_by": {
                    "type": "string",
                    "enum": [
                      "unslop",
                      "zerogpt_surrogate",
                      "desklib_surrogate",
                      "superannotate_surrogate",
                      "winston_surrogate",
                      "sapling_surrogate"
                    ],
                    "default": "unslop"
                  },
                  "sentence_scores": {
                    "type": "boolean",
                    "default": false
                  },
                  "from": {
                    "type": "string",
                    "enum": [
                      "original",
                      "result"
                    ]
                  },
                  "alternative": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "alternatives": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 3
                  },
                  "style_id": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "detectors": {
                    "type": "array",
                    "uniqueItems": true,
                    "maxItems": 12,
                    "items": {
                      "type": "string",
                      "enum": [
                        "unslop",
                        "zerogpt_surrogate",
                        "desklib_surrogate",
                        "superannotate_surrogate",
                        "winston_surrogate",
                        "sapling_surrogate",
                        "gptzero",
                        "zerogpt",
                        "sapling",
                        "winston",
                        "pangram",
                        "copyleaks"
                      ]
                    }
                  },
                  "wait": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/detect": {
      "post": {
        "summary": "Detect AI text",
        "operationId": "post_v1_detect",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Detection"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200000
                  },
                  "input_format": {
                    "type": "string",
                    "enum": [
                      "text",
                      "html",
                      "markdown"
                    ],
                    "default": "text"
                  },
                  "detectors": {
                    "type": "array",
                    "uniqueItems": true,
                    "maxItems": 12,
                    "items": {
                      "type": "string",
                      "enum": [
                        "unslop",
                        "zerogpt_surrogate",
                        "desklib_surrogate",
                        "superannotate_surrogate",
                        "winston_surrogate",
                        "sapling_surrogate",
                        "gptzero",
                        "zerogpt",
                        "sapling",
                        "winston",
                        "pangram",
                        "copyleaks"
                      ]
                    }
                  },
                  "sentence_scores": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "X-gptzero-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-zerogpt-Key",
            "in": "header",
            "description": "Provider bearer access token",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-sapling-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-winston-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-pangram-Key",
            "in": "header",
            "description": "Provider API credential",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-copyleaks-Key",
            "in": "header",
            "description": "Provider bearer access token",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/styles": {
      "post": {
        "summary": "Create a style",
        "operationId": "post_v1_styles",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Style"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StyleRequest"
              },
              "example": {
                "name": "Concise academic",
                "examples": [
                  {
                    "original": "It is important to note that the sample size was small.",
                    "rewritten": "The sample was small."
                  },
                  {
                    "original": "The results of the analysis indicate an association, rather than a causal relationship.",
                    "rewritten": "The analysis shows an association, not causation."
                  },
                  {
                    "original": "Further research is required in order to establish whether this effect persists over time.",
                    "rewritten": "Further research should test whether the effect persists."
                  }
                ]
              }
            }
          }
        }
      },
      "get": {
        "summary": "List styles",
        "operationId": "get_v1_styles",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/styles/{id}": {
      "get": {
        "summary": "Get a style",
        "operationId": "get_v1_styles__id_",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Style"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "delete": {
        "summary": "Delete a style",
        "operationId": "delete_v1_styles__id_",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/reports/compare": {
      "post": {
        "summary": "Compare preservation checks",
        "operationId": "post_v1_reports_compare",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreservationReport"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "original",
                  "rewritten"
                ],
                "properties": {
                  "original": {
                    "type": "string"
                  },
                  "rewritten": {
                    "type": "string"
                  },
                  "input_format": {
                    "type": "string",
                    "enum": [
                      "text",
                      "html",
                      "markdown"
                    ],
                    "default": "text"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Read account usage and balances",
        "operationId": "get_v1_usage",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "RewriteRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "text"
        ],
        "properties": {
          "writing_style": {
            "type": "string",
            "enum": [
              "default",
              "academic",
              "plain",
              "formal",
              "casual",
              "concise"
            ],
            "default": "default"
          },
          "strength": {
            "type": "string",
            "enum": [
              "light",
              "balanced",
              "strong"
            ],
            "default": "balanced"
          },
          "rank_by": {
            "type": "string",
            "enum": [
              "unslop",
              "zerogpt_surrogate",
              "desklib_surrogate",
              "superannotate_surrogate",
              "winston_surrogate",
              "sapling_surrogate"
            ],
            "default": "unslop"
          },
          "sentence_scores": {
            "type": "boolean",
            "default": false
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200000
          },
          "input_format": {
            "type": "string",
            "enum": [
              "text",
              "html",
              "markdown"
            ],
            "default": "text"
          },
          "alternatives": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3,
            "default": 1
          },
          "style_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "protected_text": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 5000
            }
          },
          "freeze_citations": {
            "type": "boolean",
            "default": false
          },
          "detectors": {
            "type": "array",
            "uniqueItems": true,
            "maxItems": 12,
            "items": {
              "type": "string",
              "enum": [
                "unslop",
                "zerogpt_surrogate",
                "desklib_surrogate",
                "superannotate_surrogate",
                "winston_surrogate",
                "sapling_surrogate",
                "gptzero",
                "zerogpt",
                "sapling",
                "winston",
                "pangram",
                "copyleaks"
              ]
            }
          },
          "wait": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "StyleRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "examples"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "instructions": {
            "type": "string",
            "maxLength": 2000
          },
          "examples": {
            "type": "array",
            "minItems": 3,
            "maxItems": 10,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "original",
                "rewritten"
              ],
              "properties": {
                "original": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 10000
                },
                "rewritten": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 10000
                }
              }
            }
          }
        }
      },
      "DetectorResult": {
        "type": "object",
        "required": [
          "detector",
          "status"
        ],
        "properties": {
          "detector": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "completed",
              "failed"
            ]
          },
          "score": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "metric": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "simulated": {
            "type": "boolean"
          },
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          },
          "segment_method": {
            "type": "string"
          },
          "offset_unit": {
            "type": "string"
          },
          "segments_status": {
            "type": "string"
          },
          "segments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "start": {
                  "type": "integer"
                },
                "end": {
                  "type": "integer"
                },
                "text": {
                  "type": "string"
                },
                "score": {
                  "type": "number"
                },
                "status": {
                  "type": "string"
                },
                "error": {
                  "$ref": "#/components/schemas/ErrorDetail"
                }
              }
            }
          }
        }
      },
      "ErrorDetail": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "details": {
            "type": "object"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "RewriteJob": {
        "type": "object",
        "required": [
          "id",
          "status",
          "input",
          "results"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "failed",
              "interrupted"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "provider": {
            "type": "string"
          },
          "ranking": {
            "type": "object",
            "properties": {
              "detector": {
                "type": "string"
              },
              "direction": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "best_alternative": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "input": {
            "$ref": "#/components/schemas/RewriteRequest"
          },
          "parent": {
            "type": [
              "object",
              "null"
            ]
          },
          "progress": {
            "type": "object",
            "properties": {
              "completed_units": {
                "type": "integer"
              },
              "total_units": {
                "type": "integer"
              }
            }
          },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "rank": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "ranking_score": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "text": {
                  "type": "string"
                },
                "scored_text": {
                  "type": "string"
                },
                "input_format": {
                  "type": "string",
                  "enum": [
                    "text",
                    "html",
                    "markdown"
                  ],
                  "default": "text"
                },
                "preservation": {
                  "$ref": "#/components/schemas/PreservationReport"
                },
                "detectors": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DetectorResult"
                  }
                },
                "calls": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          },
          "elapsed_ms": {
            "type": "integer"
          },
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          },
          "billing": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "reserved",
                  "settled"
                ]
              },
              "channel": {
                "type": "string",
                "enum": [
                  "API",
                  "MCP"
                ]
              },
              "input_words": {
                "type": "integer"
              },
              "requested_alternatives": {
                "type": "integer"
              },
              "reserved_included": {
                "type": "integer"
              },
              "reserved_prepaid": {
                "type": "integer"
              },
              "completed_alternatives": {
                "type": "integer"
              },
              "charged_included": {
                "type": "integer"
              },
              "charged_prepaid": {
                "type": "integer"
              },
              "prepaid_usd": {
                "type": "number"
              }
            }
          }
        }
      },
      "PreservationReport": {
        "type": "object",
        "properties": {
          "words_in": {
            "type": "integer"
          },
          "words_out": {
            "type": "integer"
          },
          "length_ratio": {
            "type": [
              "number",
              "null"
            ]
          },
          "figures_kept": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "figures_missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "figures_added": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "citations_missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "changed": {
            "type": "boolean"
          },
          "semantic_evaluation": {
            "type": "boolean",
            "const": false
          },
          "frozen_items": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "unchanged_short_spans": {
            "type": "integer"
          }
        }
      },
      "Style": {
        "allOf": [
          {
            "$ref": "#/components/schemas/StyleRequest"
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "profile": {
                "type": "object"
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        ]
      },
      "Detection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "completed",
              "partial",
              "failed"
            ]
          },
          "words": {
            "type": "integer"
          },
          "scored_text": {
            "type": "string"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DetectorResult"
            }
          }
        }
      }
    }
  }
}
