{
    "openapi": "3.1.0",
    "info": {
        "title": "korrektur.de Scan API",
        "version": "1.0.0",
        "description": "Plagiats- und KI-Pruefungen fuer verifizierte Geschaeftskonten mit Prepaid-Credits. Ein Credit gilt je angefangene 250 Woerter."
    },
    "servers": [
        {
            "url": "https://korrektur.de/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/jobs": {
            "post": {
                "summary": "Scan anlegen",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "minLength": 8,
                            "maxLength": 128
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "file",
                                    "mode"
                                ],
                                "properties": {
                                    "file": {
                                        "type": "string",
                                        "format": "binary"
                                    },
                                    "mode": {
                                        "type": "string",
                                        "enum": [
                                            "plagiarism",
                                            "ai",
                                            "combined"
                                        ],
                                        "default": "combined"
                                    },
                                    "webhook_url": {
                                        "type": "string",
                                        "format": "uri"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "$ref": "#/components/responses/Job"
                    },
                    "402": {
                        "$ref": "#/components/responses/Error"
                    },
                    "422": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        },
        "/jobs/{job_id}": {
            "get": {
                "summary": "Scanstatus und Ergebnis abrufen",
                "parameters": [
                    {
                        "name": "job_id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/Job"
                    },
                    "404": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        },
        "/credits": {
            "get": {
                "summary": "Guthaben und letzte Buchungen abrufen",
                "responses": {
                    "200": {
                        "description": "Credit-Konto",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "balance_credits",
                                        "transactions"
                                    ],
                                    "properties": {
                                        "balance_credits": {
                                            "type": "integer"
                                        },
                                        "transactions": {
                                            "type": "array",
                                            "items": {
                                                "type": "object"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "kd_live_*"
            }
        },
        "schemas": {
            "Job": {
                "type": "object",
                "required": [
                    "id",
                    "status",
                    "mode",
                    "words",
                    "credits"
                ],
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "queued",
                            "processing",
                            "completed",
                            "failed",
                            "expired"
                        ]
                    },
                    "mode": {
                        "type": "string"
                    },
                    "filename": {
                        "type": "string"
                    },
                    "words": {
                        "type": "integer"
                    },
                    "credits": {
                        "type": "integer"
                    },
                    "metrics": {
                        "type": "object"
                    },
                    "report_url": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "uri"
                    },
                    "report_password": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "files": {
                        "type": "array",
                        "items": {
                            "type": "object"
                        }
                    }
                }
            },
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "responses": {
            "Job": {
                "description": "Scanauftrag",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Job"
                        }
                    }
                }
            },
            "Error": {
                "description": "Fehler",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            }
        }
    }
}