{
  "openapi": "3.1.0",
  "info": {
    "title": "Polimake API",
    "version": "0.1.0-preview",
    "summary": "Preview API contract for Polimake developer integrations.",
    "description": "This OpenAPI document is a preview contract for agent-friendly and developer-facing documentation. Endpoint names, fields and limits may change before general availability."
  },
  "servers": [
    {
      "url": "https://api.polimake.com/v1",
      "description": "Production API preview"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/media/search": {
      "post": {
        "operationId": "searchMedia",
        "summary": "Search media assets with natural language",
        "description": "Search a project for media objects using semantic search over metadata, AI descriptions and visual context.",
        "tags": ["Media"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchMediaRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchMediaResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/media/{media_id}": {
      "get": {
        "operationId": "getMedia",
        "summary": "Retrieve a media object",
        "description": "Return metadata and AI analysis for a media object.",
        "tags": ["Media"],
        "parameters": [
          {
            "name": "media_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Media object",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MediaObject"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Use an API key in the Authorization header: Bearer YOUR_API_KEY"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Forbidden": {
        "description": "API key cannot access this resource",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "SearchMediaRequest": {
        "type": "object",
        "required": ["project_id", "query"],
        "properties": {
          "project_id": {
            "type": "string",
            "description": "Project to search in."
          },
          "query": {
            "type": "string",
            "description": "Natural-language search query."
          },
          "top_k": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 10
          },
          "mime_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "filters": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "SearchMediaResponse": {
        "type": "object",
        "required": ["object", "query", "items"],
        "properties": {
          "object": {
            "type": "string",
            "const": "search_result"
          },
          "query": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MediaObject"
            }
          }
        }
      },
      "MediaObject": {
        "type": "object",
        "required": ["id", "object", "project_id", "filename", "mime_type", "status"],
        "properties": {
          "id": {
            "type": "string",
            "example": "media_01HX9R8K4Q2Z4T"
          },
          "object": {
            "type": "string",
            "const": "media_object"
          },
          "score": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "project_id": {
            "type": "string"
          },
          "filename": {
            "type": "string"
          },
          "mime_type": {
            "type": "string"
          },
          "size_bytes": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": ["uploading", "processing", "ready", "failed", "deleted"]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "urls": {
            "type": "object",
            "properties": {
              "preview": {
                "type": "string",
                "format": "uri"
              },
              "thumbnail": {
                "type": "string",
                "format": "uri"
              }
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "ai": {
            "type": "object",
            "properties": {
              "description": {
                "type": "string"
              },
              "tags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "objects": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "suggested_uses": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": true
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["type", "message"],
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Media",
      "description": "Media search and media object operations."
    }
  ]
}
