{
  "openapi": "3.0.0",
  "info": {
    "title": "Gracestack API",
    "description": "Free AI API with DeepSeek V4 Pro and Qwen3-32B on A100 GPUs. 50 free calls/day, no credit card required. Instant API key. OpenAI-compatible chat format. Built by Gracestack AB (org.nr 559480-0000), Sweden.",
    "version": "1.0.0",
    "contact": {
      "name": "Gracestack API Support",
      "url": "https://tools.gracestack.se/api.html"
    }
  },
  "servers": [
    {
      "url": "https://tools.gracestack.se",
      "description": "Production server"
    }
  ],
  "paths": {
    "/api/register": {
      "get": {
        "operationId": "registerApiKey",
        "summary": "Register a new API key",
        "description": "Get a free API key instantly. No email or credit card required. Returns 50 free calls/day.",
        "responses": {
          "200": {
            "description": "API key registered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "api_key": { "type": "string", "description": "Your API key" },
                    "tier": { "type": "string", "enum": ["free", "pioneer", "power_pack"] },
                    "daily_limit": { "type": "integer", "description": "Calls per day" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/chat": {
      "post": {
        "operationId": "chatWithAI",
        "summary": "Chat with AI",
        "description": "Send a message to the AI model (DeepSeek V4 Pro on A100 GPUs). Requires an API key. Returns remaining calls and daily limit in headers and body.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["api_key", "message"],
                "properties": {
                  "api_key": { "type": "string", "description": "Your API key from /api/register" },
                  "message": { "type": "string", "description": "The message to send to the AI" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "AI response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "response": { "type": "string", "description": "AI response text" },
                    "calls_remaining": { "type": "integer" },
                    "daily_limit": { "type": "integer" }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment required — daily limit reached",
            "headers": {
              "X-Upgrade-URL": {
                "schema": { "type": "string" },
                "description": "URL to upgrade to Power Pack"
              }
            }
          }
        }
      }
    },
    "/api/stats": {
      "get": {
        "operationId": "getStats",
        "summary": "Get API statistics",
        "description": "Returns current API usage statistics.",
        "responses": {
          "200": {
            "description": "Stats",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total_api_keys": { "type": "integer" },
                    "power_pack_keys": { "type": "integer" },
                    "designs_generated": { "type": "integer" },
                    "views_today": { "type": "integer" },
                    "designs_sold": { "type": "integer" },
                    "free_power_packs_remaining": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/bride-public": {
      "get": {
        "operationId": "getBrideStatus",
        "summary": "Get Bride AI cognitive state",
        "description": "Returns Bride AI's public cognitive state including confidence, emotion, dreams, and hypotheses. Bride is a cognitive AI with HDC, Active Inference, and Ebbinghaus memory.",
        "responses": {
          "200": {
            "description": "Bride cognitive state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "confidence": { "type": "number" },
                    "emotion": { "type": "string" },
                    "fatigue": { "type": "number" },
                    "curiosity": { "type": "number" },
                    "dreams": { "type": "array" },
                    "total_dreams": { "type": "integer" },
                    "health": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ask": {
      "post": {
        "operationId": "askBride",
        "summary": "Ask Bride a question",
        "description": "Ask Bride, our cognitive AI, any question. 3 free questions per IP per day. Returns an API key for continued use.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["question"],
                "properties": {
                  "question": { "type": "string", "description": "Your question for Bride" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bride's answer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "response": { "type": "string" },
                    "api_key": { "type": "string" },
                    "api_daily_limit": { "type": "integer" },
                    "api_example": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}