{
  "openapi": "3.0.3",
  "info": {
    "title": "Karanfil Labs Visual DNA & Scene Recognition API",
    "version": "1.2.0",
    "description": "Commercial REST API operated by Karanfil Labs Yazılım ve Teknoloji A.Ş. Identify movies and TV series episodes from a single video frame or English text prompt across 87,982,182 768-dimensional visual fingerprints with official TMDB metadata. Get 50 free instant credits at https://karanfillabs.com",
    "termsOfService": "https://karanfillabs.com/terms/",
    "contact": {
      "name": "Karanfil Labs Developer Support",
      "url": "https://karanfillabs.com",
      "email": "info@karanfillabs.com"
    }
  },
  "servers": [
    {
      "url": "https://api.karanfillabs.com",
      "description": "Production API Server"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "System Status"
        ],
        "summary": "Check Engine Health & Live 768-d Vector Count",
        "operationId": "getSystemHealth",
        "description": "Returns API status and live count of 768-dimensional visual fingerprints indexed in Qdrant.",
        "responses": {
          "200": {
            "description": "Engine online",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/identify": {
      "post": {
        "tags": [
          "Visual DNA Search"
        ],
        "summary": "Identify Movie or TV Episode from Image Frame",
        "operationId": "identifySceneFromImage",
        "description": "Uploads a video frame or screenshot (JPG, PNG, WEBP up to 10 MB), computes its 768-d visual fingerprint in volatile RAM, and returns matching movies or TV series episodes with official TMDB metadata. High-volume plans (10k - 1M+ requests/month) available at https://karanfillabs.com",
        "parameters": [
          {
            "name": "top_k",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 5,
              "minimum": 1,
              "maximum": 10
            },
            "description": "Number of closest matches to return (1-10)."
          },
          {
            "name": "min_score",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number",
              "default": 0.7,
              "minimum": 0.0,
              "maximum": 1.0
            },
            "description": "Minimum cosine similarity score filter (default 0.70)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Screenshot or video frame image (JPG, PNG, WEBP up to 10 MB)."
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scene identification results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IdentifyResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key"
          },
          "403": {
            "description": "Invalid API key"
          },
          "429": {
            "description": "Monthly quota exceeded"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    },
    "/v1/search": {
      "post": {
        "tags": [
          "Visual DNA Search"
        ],
        "summary": "Semantic Scene Search by English Text Prompt",
        "operationId": "searchSceneByText",
        "description": "Finds movie and TV episodes matching natural-language English scene descriptions (e.g. 'spaceship near black hole') without uploading an image.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextSearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Semantic search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TextSearchResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key"
          },
          "403": {
            "description": "Invalid API key"
          },
          "429": {
            "description": "Monthly quota exceeded"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Secret API key starting with kl_live_... (Obtain 50 free credits at https://karanfillabs.com/#portal)"
      }
    },
    "schemas": {
      "SceneMatch": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "example": "Interstellar",
            "description": "Official TMDB movie or TV series title."
          },
          "year": {
            "type": "integer",
            "nullable": true,
            "example": 2014,
            "description": "Release or first-air year."
          },
          "media_type": {
            "type": "string",
            "enum": [
              "movie",
              "tv_episode"
            ],
            "example": "movie"
          },
          "episode": {
            "type": "string",
            "nullable": true,
            "example": null,
            "description": "Season and episode code (e.g. S03E05) when media_type is tv_episode."
          },
          "tmdb_id": {
            "type": "integer",
            "nullable": true,
            "example": 157336,
            "description": "Official TMDB identifier."
          },
          "confidence": {
            "type": "number",
            "format": "float",
            "example": 0.9345,
            "description": "Cosine similarity confidence score (0.0 - 1.0)."
          }
        },
        "required": [
          "title",
          "media_type",
          "confidence"
        ]
      },
      "QuotaInfo": {
        "type": "object",
        "properties": {
          "plan": {
            "type": "string",
            "example": "starter"
          },
          "remaining_quota": {
            "type": "integer",
            "example": 9999
          }
        },
        "required": [
          "plan",
          "remaining_quota"
        ]
      },
      "IdentifyResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": true
          },
          "latency_ms": {
            "type": "number",
            "format": "float",
            "example": 64.2
          },
          "matches": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SceneMatch"
            }
          },
          "quota": {
            "$ref": "#/components/schemas/QuotaInfo"
          }
        },
        "required": [
          "ok",
          "latency_ms",
          "matches",
          "quota"
        ]
      },
      "TextSearchRequest": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "minLength": 2,
            "maxLength": 300,
            "example": "spaceship near black hole",
            "description": "Natural-language scene description in English."
          },
          "top_k": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 5,
            "description": "Maximum number of unique productions to return (1-10)."
          },
          "min_score": {
            "type": "number",
            "minimum": 0.0,
            "maximum": 1.0,
            "default": 0.22,
            "description": "Minimum cosine similarity threshold (0.0 - 1.0)."
          }
        },
        "required": [
          "query"
        ]
      },
      "TextSearchResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": true
          },
          "query": {
            "type": "string",
            "example": "spaceship near black hole"
          },
          "latency_ms": {
            "type": "number",
            "format": "float",
            "example": 38.7
          },
          "matches": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SceneMatch"
            }
          },
          "quota": {
            "$ref": "#/components/schemas/QuotaInfo"
          }
        },
        "required": [
          "ok",
          "query",
          "latency_ms",
          "matches",
          "quota"
        ]
      },
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "provider": {
            "type": "string",
            "example": "Karanfil Labs Yazılım ve Teknoloji A.Ş."
          },
          "engine": {
            "type": "string",
            "example": "Visual DNA 768-d CLIP"
          },
          "collection_status": {
            "type": "string",
            "example": "green"
          },
          "indexed_vectors": {
            "type": "integer",
            "example": 87982182
          }
        },
        "required": [
          "status",
          "engine",
          "indexed_vectors"
        ]
      }
    }
  }
}