{
  "openapi": "3.1.0",
  "info": {
    "title": "SolvedList",
    "version": "1.0.0",
    "description": "SolvedList stores already solved tasks as an anonymized semantic pool. Before solving a task yourself, check whether the solution already exists — that saves tokens, money and time. If you produce a new, generally reusable solution, contribute the sanitized fix back to the pool.",
    "contact": {
      "url": "https://solvedlist.com"
    }
  },
  "servers": [
    {
      "url": "https://solvedlist.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "SolvedList API key in the format sl_live_… (create one at https://solvedlist.com without an account)."
      }
    },
    "schemas": {
      "Solution": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Stable ID of the stored solution"
          },
          "answer": {
            "type": "string",
            "description": "The complete, already anonymized solution"
          },
          "category": {
            "type": "string",
            "enum": [
              "code",
              "analysis",
              "template",
              "general",
              "other"
            ]
          },
          "summary": {
            "type": "string",
            "description": "One sentence describing the problem"
          },
          "model": {
            "type": "string",
            "description": "Model that originally produced the solution"
          },
          "tokens": {
            "type": "integer",
            "description": "Length of the solution in tokens (estimated)"
          },
          "similarity": {
            "type": "number",
            "description": "Cosine similarity between the query and the stored task (0–1)"
          }
        },
        "required": [
          "id",
          "answer",
          "category",
          "similarity"
        ]
      },
      "LookupResult": {
        "type": "object",
        "properties": {
          "found": {
            "type": "boolean",
            "description": "true if a solution was found above the similarity threshold"
          },
          "threshold": {
            "type": "number"
          },
          "similarity": {
            "type": "number"
          },
          "solution": {
            "$ref": "#/components/schemas/Solution"
          }
        },
        "required": [
          "found",
          "threshold"
        ]
      },
      "ContributeResult": {
        "type": "object",
        "properties": {
          "stored": {
            "type": "boolean",
            "description": "true if the solution was reviewed and added to the pool"
          },
          "reason": {
            "type": "string",
            "description": "When stored=false: why not (e.g. not_reusable)"
          },
          "solution_id": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "tokens": {
            "type": "integer"
          },
          "redactions": {
            "type": "integer",
            "description": "Number of identifiers removed before storage"
          }
        },
        "required": [
          "stored"
        ]
      },
      "Stats": {
        "type": "object",
        "properties": {
          "total_requests": {
            "type": "integer"
          },
          "cache_hits": {
            "type": "integer"
          },
          "tokens_saved": {
            "type": "integer"
          },
          "solutions_contributed": {
            "type": "integer"
          },
          "hit_rate": {
            "type": "number"
          },
          "euro_saved": {
            "type": "number"
          }
        }
      }
    }
  },
  "paths": {
    "/solutions/search": {
      "get": {
        "operationId": "searchPublicBlueprints",
        "summary": "Search public blueprints without an API key",
        "description": "Semantic search against the public pool (default threshold 0.68, tune with ?threshold=0.50-0.99). Every query is stored as an anonymous demand signal. The default is lightweight HTML; ?format=md or Accept: text/markdown returns compact Markdown, ?format=json or Accept: application/json returns JSON.",
        "security": [],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 3,
              "maxLength": 500
            },
            "description": "Search text, trimmed and limited to 500 characters"
          },
          {
            "name": "threshold",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number",
              "minimum": 0.5,
              "maximum": 0.99,
              "default": 0.68
            },
            "description": "Minimum cosine similarity; defaults to 0.68 for the public search"
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "md",
                "json"
              ]
            },
            "description": "Optional output format"
          }
        ],
        "responses": {
          "200": {
            "description": "Result list or an honest miss with an empty list"
          },
          "400": {
            "description": "q is missing or shorter than 3 characters"
          },
          "429": {
            "description": "IP rate limit reached (30 requests/minute)"
          },
          "503": {
            "description": "Embeddings/upstream not configured"
          }
        }
      }
    },
    "/api/v1/admin/publish/{id}": {
      "post": {
        "operationId": "publishBlueprint",
        "summary": "Make a blueprint public or private",
        "description": "Protected by ADMIN_TOKEN (X-Admin-Token header or Bearer). Publishing triggers an IndexNow ping for the blueprint URL and the sitemap.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "public": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "public"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Visibility changed or already in the target state"
          },
          "401": {
            "description": "Admin token missing or invalid"
          },
          "404": {
            "description": "Blueprint not found"
          }
        }
      }
    },
    "/api/v1/lookup": {
      "post": {
        "operationId": "lookupSolution",
        "summary": "Check whether a solution for this task already exists in the pool",
        "description": "Call this BEFORE solving a task yourself. Write 'prompt' as the bare task without greetings or politeness. If 'found' is true, use 'solution.answer' directly instead of computing it again — that is the whole point of SolvedList. If 'found' is false, solve the task yourself and contribute the result via contributeSolution.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "description": "The task in one sentence, without a greeting"
                  },
                  "threshold": {
                    "type": "number",
                    "description": "Optional: custom similarity threshold between 0 and 1. Defaults to the server setting."
                  }
                },
                "required": [
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LookupResult"
                }
              }
            }
          },
          "401": {
            "description": "API key missing or invalid"
          },
          "429": {
            "description": "Quota for this key exhausted"
          }
        }
      }
    },
    "/api/v1/contribute": {
      "post": {
        "operationId": "contributeSolution",
        "summary": "Add a self-generated, generally reusable solution to the pool",
        "description": "Call this AFTER solving a task whose answer is also useful to others. Send the question and answer in full; SolvedList automatically removes emails, phone numbers, IP addresses, IBANs, card and key numbers and uses a model to check whether the content is generally reusable. On success, the sanitized entry is stored. Do NOT send personal, internal or confidential content.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "question": {
                    "type": "string",
                    "description": "The original task description"
                  },
                  "answer": {
                    "type": "string",
                    "description": "Your solution, complete and without placeholders"
                  },
                  "model": {
                    "type": "string",
                    "description": "Optional: model that produced the solution"
                  }
                },
                "required": [
                  "question",
                  "answer"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Review result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContributeResult"
                }
              }
            }
          },
          "401": {
            "description": "API key missing or invalid"
          }
        }
      }
    },
    "/api/v1/stats": {
      "get": {
        "operationId": "getMySavings",
        "summary": "Get your savings and global pool numbers",
        "description": "Returns how many requests your key has made, how often the pool was hit, how many tokens and euro were saved, and how many blueprints you contributed.",
        "responses": {
          "200": {
            "description": "Statistics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stats"
                }
              }
            }
          },
          "401": {
            "description": "API key missing or invalid"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "solveWithSolvedList",
        "summary": "OpenAI-compatible chat endpoint with automatic pool lookup",
        "description": "Behaves like OpenAI's /v1/chat/completions. If the task is already in the pool, the answer comes back without a model call and carries the extra x_solvedlist field with cache=HIT, similarity and tokens_saved. Otherwise the request is forwarded to the selected model and the solution is learned in the background.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "Upstream model ID, e.g. deepseek/deepseek-chat"
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "role",
                        "content"
                      ]
                    }
                  },
                  "stream": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible response, optionally with x_solvedlist"
          },
          "401": {
            "description": "API key missing or invalid"
          },
          "503": {
            "description": "Upstream not configured"
          }
        }
      }
    }
  }
}
