{
  "openapi": "3.0.3",
  "info": {
    "title": "Prompt Optimizer API",
    "version": "1.0.0",
    "description": "Publiczne API Prompt Optimizera. Zamień surową myśl w gotowy, zoptymalizowany prompt jednym wywołaniem. Uwierzytelnianie kluczem API (nagłówek X-API-Key). Klucze generujesz w panelu konta: /optimizer/account.html#api-keys",
    "contact": { "name": "AI Evolution", "url": "https://sukcesai.com/optimizer/" }
  },
  "servers": [
    { "url": "https://sukcesai.com/optimizer/api/v1", "description": "Produkcja" }
  ],
  "security": [ { "ApiKeyAuth": [] } ],
  "paths": {
    "/optimize.php": {
      "post": {
        "summary": "Optymalizuj prompt (jednostrzałowo)",
        "description": "Przyjmuje surowy opis tego, czego potrzebujesz, i zwraca gotowy, ustrukturyzowany prompt zbudowany tym samym silnikiem co interaktywny edytor. Zużywa jedną generację z miesięcznego limitu konta.",
        "operationId": "optimizePrompt",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/OptimizeRequest" },
              "examples": {
                "mail_b2b": {
                  "summary": "Mail B2B",
                  "value": { "input": "profesjonalny mail do klienta B2B z przypomnieniem o zaległej fakturze, ton stanowczy ale uprzejmy" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wygenerowany prompt",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OptimizeResponse" } } }
          },
          "401": { "description": "Brak lub nieprawidłowy klucz API", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Przekroczony miesięczny limit generacji", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LimitError" } } } },
          "422": { "description": "Nieprawidłowe dane wejściowe", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Przekroczony limit zapytań (20/min)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "502": { "description": "Błąd generacji po stronie modelu", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-Key", "description": "Klucz API z panelu konta (/optimizer/account.html#api-keys)." }
    },
    "schemas": {
      "OptimizeRequest": {
        "type": "object",
        "required": ["input"],
        "properties": {
          "input": { "type": "string", "maxLength": 5000, "description": "Surowa myśl / opis czego potrzebujesz (alias: raw_thoughts).", "example": "post na LinkedIn o premierze naszego narzędzia AI dla marketerów" },
          "answers": { "type": "object", "description": "Opcjonalne doprecyzowanie (ton, długość, odbiorca). Zwykle puste przy wywołaniu jednostrzałowym.", "additionalProperties": true },
          "preset": { "type": "string", "description": "Opcjonalny preset (slug lub ID) zawężający styl/kontekst.", "example": "linkedin-post" }
        }
      },
      "OptimizeResponse": {
        "type": "object",
        "properties": {
          "prompt": { "type": "string", "description": "Gotowy, zoptymalizowany prompt." },
          "run_id": { "type": "integer", "description": "ID generacji (widoczne też w historii konta)." },
          "model": { "type": "string", "example": "gpt-4o-mini" },
          "tokens_used": { "type": "integer" },
          "cost_usd": { "type": "number", "format": "float" },
          "usage": {
            "type": "object",
            "properties": {
              "requests_today": { "type": "integer", "nullable": true },
              "requests_month": { "type": "integer", "nullable": true }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "example": "invalid_input" },
          "message": { "type": "string" }
        }
      },
      "LimitError": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "example": "limit_exceeded" },
          "message": { "type": "string" },
          "current": { "type": "integer" },
          "limit": { "type": "integer" },
          "upgrade_required": { "type": "boolean" }
        }
      }
    }
  }
}
