{
  "openapi": "3.0.3",
  "info": {
    "title": "Transcribe Web API",
    "version": "1.0.0",
    "description": "OpenAPI description for the transcript edge routes and lightweight media backend used by the static web app.",
    "contact": {
      "name": "Transcribe",
      "url": "https://transcribe.panchamkhaitan.com"
    }
  },
  "servers": [
    {
      "url": "/",
      "description": "Current deployment origin"
    }
  ],
  "tags": [
    {
      "name": "Transcripts",
      "description": "Transcript resolution and shared-cache endpoints."
    },
    {
      "name": "Proxy",
      "description": "Proxy routes that expose media metadata and streaming media."
    }
  ],
  "paths": {
    "/api/transcripts/resolve": {
      "post": {
        "tags": [
          "Transcripts"
        ],
        "summary": "Resolve the best available transcript",
        "description": "Primary transcript endpoint. Checks shared cache, then YouTube captions, and returns a normalized response shape.",
        "operationId": "resolveTranscript",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TranscriptResolveRequest"
              },
              "example": {
                "url": "https://www.youtube.com/watch?v=abc123",
                "resolution": "prefer_captions",
                "segments": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resolver completed successfully, including `found: false` outcomes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TranscriptResolveResponse"
                },
                "example": {
                  "found": true,
                  "cached": false,
                  "platform": "youtube",
                  "canonicalUrl": "https://www.youtube.com/watch?v=abc123",
                  "mediaId": "abc123",
                  "source": "youtube_captions",
                  "provider": "yt_dlp",
                  "captionType": "creator",
                  "captionLabel": "Creator captions",
                  "language": "en",
                  "contentHash": "sha256:example",
                  "resolvedAt": "2026-04-21T10:00:00+00:00",
                  "transcription": {
                    "text": "Hello and welcome.",
                    "segments": [
                      {
                        "start": 0,
                        "end": 2.4,
                        "text": "Hello and welcome."
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unsupported or invalid media URL.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Invalid request schema.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected resolver failure.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/proxy/video-info": {
      "get": {
        "servers": [
          {
            "url": "https://transcribe-video-backend.up.railway.app",
            "description": "Lightweight media backend"
          }
        ],
        "tags": [
          "Proxy"
        ],
        "summary": "Fetch remote video metadata",
        "operationId": "getVideoInfo",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Absolute remote media URL."
          }
        ],
        "responses": {
          "200": {
            "description": "Video metadata response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VideoInfoResponse"
                },
                "example": {
                  "title": "Example video",
                  "uploader": "Transcribe",
                  "upload_date": "20260412",
                  "duration": 73,
                  "thumbnail": "https://i.ytimg.com/vi/abc123/hqdefault.jpg",
                  "view_count": 48213,
                  "like_count": 1542
                }
              }
            }
          },
          "400": {
            "description": "Missing URL parameter.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Metadata lookup failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/proxy/video": {
      "get": {
        "servers": [
          {
            "url": "https://transcribe-video-backend.up.railway.app",
            "description": "Lightweight media backend"
          }
        ],
        "tags": [
          "Proxy"
        ],
        "summary": "Proxy a remote video stream",
        "operationId": "proxyVideo",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Absolute remote media URL."
          }
        ],
        "responses": {
          "200": {
            "description": "Binary video response.",
            "content": {
              "video/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Missing or unsupported URL.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Video proxy failure.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TranscriptResolveRequest": {
        "type": "object",
        "required": [
          "url",
          "resolution"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "resolution": {
            "type": "string",
            "enum": [
              "captions_only",
              "prefer_captions"
            ]
          },
          "segments": {
            "type": "boolean",
            "default": false,
            "description": "Include timestamped transcript segments in the response."
          }
        }
      },
      "TranscriptSegment": {
        "type": "object",
        "required": [
          "start",
          "end",
          "text"
        ],
        "properties": {
          "start": {
            "type": "number",
            "format": "float"
          },
          "end": {
            "type": "number",
            "format": "float"
          },
          "text": {
            "type": "string"
          }
        }
      },
      "TranscriptPayload": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string"
          },
          "language": {
            "type": "string",
            "nullable": true
          },
          "segments": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/TranscriptSegment"
            }
          }
        }
      },
      "TranscriptResolveResponse": {
        "type": "object",
        "required": [
          "found",
          "cached"
        ],
        "properties": {
          "found": {
            "type": "boolean"
          },
          "cached": {
            "type": "boolean"
          },
          "platform": {
            "type": "string",
            "nullable": true,
            "enum": [
              "instagram",
              "youtube",
              "twitter",
              "direct_video"
            ]
          },
          "canonicalUrl": {
            "type": "string",
            "nullable": true
          },
          "mediaId": {
            "type": "string",
            "nullable": true
          },
          "source": {
            "type": "string",
            "nullable": true,
            "enum": [
              "cache",
              "youtube_captions",
              "generated_transcription"
            ]
          },
          "provider": {
            "type": "string",
            "nullable": true,
            "enum": [
              "cache",
              "youtube_api",
              "yt_dlp",
              "speech_to_text"
            ]
          },
          "captionType": {
            "type": "string",
            "nullable": true,
            "enum": [
              "creator",
              "auto_generated"
            ]
          },
          "captionLabel": {
            "type": "string",
            "nullable": true
          },
          "language": {
            "type": "string",
            "nullable": true
          },
          "contentHash": {
            "type": "string",
            "nullable": true
          },
          "resolvedAt": {
            "type": "string",
            "nullable": true,
            "format": "date-time"
          },
          "transcriptionEngine": {
            "type": "string",
            "nullable": true
          },
          "transcriptionModel": {
            "type": "string",
            "nullable": true
          },
          "transcription": {
            "allOf": [
              {
                "$ref": "#/components/schemas/TranscriptPayload"
              }
            ],
            "nullable": true
          },
          "reason": {
            "type": "string",
            "nullable": true,
            "enum": [
              "captions_not_found",
              "captions_disabled",
              "provider_unavailable",
              "unsupported_url",
              "transcription_unavailable"
            ]
          }
        }
      },
      "VideoInfoResponse": {
        "type": "object",
        "properties": {
          "duration": {
            "type": "number",
            "format": "float"
          },
          "like_count": {
            "type": "integer"
          },
          "thumbnail": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "upload_date": {
            "type": "string"
          },
          "uploader": {
            "type": "string"
          },
          "view_count": {
            "type": "integer"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "details": {
            "type": "string",
            "nullable": true
          },
          "found": {
            "type": "boolean",
            "nullable": true
          }
        }
      }
    }
  }
}