{
  "openapi": "3.1.0",
  "info": {
    "title": "Andebet Ethiopian Speech Intelligence API",
    "version": "1.0.0",
    "description": "Production REST API for speech-to-text, speaker diarization, sub-second timestamp alignment, and verifiable evidence grounding across Ethiopian languages (Amharic, Afaan Oromo, Tigrinya, and Ethiopian English).",
    "contact": {
      "name": "Andebet Developer Relations",
      "url": "https://andebetai.com/developers",
      "email": "dev@andebetai.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://andebetai.com/legal/terms"
    }
  },
  "servers": [
    {
      "url": "https://api.andebet.ai",
      "description": "Production Speech Cloud Gateway"
    },
    {
      "url": "http://localhost:3000/api",
      "description": "Local Development / Sandbox Environment"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/v1/transcriptions": {
      "post": {
        "summary": "Create Transcription",
        "description": "Submit spoken audio for multilingual transcription, speaker diarization, and verifiable citation extraction.\n\n### Execution Behavior:\n- **Synchronous (`200 OK`)**: Audio files $\\le$ 120 seconds ($\\le$ 25 MB) are processed in real time and return complete speaker segments and evidence directly in the HTTP response.\n- **Asynchronous (`202 Accepted`)**: Files $>$ 120 seconds (up to 4 hours / 500 MB) or requests specifying `async=true` return a job ID immediately for status polling or automated webhook callbacks.",
        "operationId": "createTranscription",
        "tags": ["Transcriptions"],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Unique UUID v4 to prevent duplicate transcription execution and double-billing on network retries.",
            "schema": {
              "type": "string",
              "format": "uuid",
              "example": "7f4c9a81-140b-482d-88b9-e15a1fbe7890"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Audio recording file (MP3, WAV, FLAC, M4A, AAC, OGG Opus). Max 25 MB for synchronous processing; up to 500 MB for asynchronous processing."
                  },
                  "language": {
                    "type": "string",
                    "enum": ["auto", "am", "om", "ti", "en"],
                    "default": "auto",
                    "description": "Spoken language code: `auto` (automatic acoustic detection), `am` (Amharic / አማርኛ), `om` (Afaan Oromo), `ti` (Tigrinya / ትግርኛ), `en` (Ethiopian English)."
                  },
                  "diarization": {
                    "type": "boolean",
                    "default": true,
                    "description": "Identify multiple speakers and assign persistent speaker IDs (`spk_01`, `spk_02`)."
                  },
                  "evidence_timestamps": {
                    "type": "boolean",
                    "default": true,
                    "description": "Generate grounded audio timestamp markers for citation verification."
                  },
                  "format": {
                    "type": "string",
                    "enum": ["json", "srt", "vtt", "text"],
                    "default": "json",
                    "description": "Output format: `json` (complete structured metadata), `srt` (SubRip subtitle file for video/YouTube), `vtt` (WebVTT subtitle file), or `text` (clean dialogue transcript)."
                  },
                  "webhook_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Target HTTPS destination for `transcription.completed` event dispatch."
                  },
                  "async": {
                    "type": "boolean",
                    "default": false,
                    "description": "Force asynchronous queueing (`202 Accepted`) regardless of file duration."
                  }
                },
                "required": ["file"]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "audio_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Publicly accessible HTTPS URL pointing directly to an audio media file (MP3, WAV, M4A, etc.). Note: Webpage URLs like YouTube links must have their audio extracted first."
                  },
                  "language": {
                    "type": "string",
                    "enum": ["auto", "am", "om", "ti", "en"],
                    "default": "auto"
                  },
                  "diarization": {
                    "type": "boolean",
                    "default": true
                  },
                  "evidence_timestamps": {
                    "type": "boolean",
                    "default": true
                  },
                  "format": {
                    "type": "string",
                    "enum": ["json", "srt", "vtt", "text"],
                    "default": "json",
                    "description": "Output format: `json` (complete structured metadata), `srt` (SubRip subtitles), `vtt` (WebVTT subtitles), or `text` (plain dialogue)."
                  },
                  "webhook_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "async": {
                    "type": "boolean",
                    "default": false
                  }
                },
                "required": ["audio_url"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transcription completed synchronously. Returns full speaker dialogue and evidence citations.",
            "headers": {
              "x-request-id": {
                "schema": { "type": "string" },
                "description": "Unique request trace identifier"
              },
              "x-ratelimit-limit": {
                "schema": { "type": "integer" },
                "description": "Allowed requests per minute window"
              },
              "x-ratelimit-remaining": {
                "schema": { "type": "integer" },
                "description": "Remaining requests in current minute window"
              },
              "x-processing-time-ms": {
                "schema": { "type": "integer" },
                "description": "Total execution latency in milliseconds"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TranscriptionCompletedResponse"
                }
              }
            }
          },
          "202": {
            "description": "Transcription queued asynchronously. Poll status or await webhook dispatch.",
            "headers": {
              "x-request-id": {
                "schema": { "type": "string" }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TranscriptionQueuedResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters or unsupported audio format.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Bearer authentication key.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. Check Retry-After header.",
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "Seconds to wait before retrying"
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Query Transcription Job by ID",
        "description": "Check the status and retrieve results for a transcription job using query parameter `?id=tra_...`.",
        "operationId": "getTranscriptionByQuery",
        "tags": ["Transcriptions"],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "The transcription job identifier (e.g. `tra_01J8YV9X2KM04`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Export format: `json` (default), `srt` (SubRip file), `vtt` (WebVTT file), or `text` (plain dialogue).",
            "schema": {
              "type": "string",
              "enum": ["json", "srt", "vtt", "text"],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Transcription job status and results.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TranscriptionCompletedResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized. Missing or invalid Bearer token.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "404": {
            "description": "Job not found or belonging to another workspace.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/transcriptions/{id}": {
      "get": {
        "summary": "Get Transcription by Path ID",
        "description": "Canonical REST endpoint to poll job progress and retrieve completed transcripts.",
        "operationId": "getTranscriptionById",
        "tags": ["Transcriptions"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The unique transcription ID returned by POST /v1/transcriptions.",
            "schema": {
              "type": "string",
              "example": "tra_01J8YV9X2KM04"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Export format: `json` (default), `srt` (SubRip file), `vtt` (WebVTT file), or `text` (plain dialogue).",
            "schema": {
              "type": "string",
              "enum": ["json", "srt", "vtt", "text"],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current status and transcription output.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TranscriptionCompletedResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Bearer authentication key.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "404": {
            "description": "Transcription job not found.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "and_live_... or and_dev_...",
        "description": "Standard HTTP Bearer token. Create keys in your Andebet Developer Console at /developers/keys."
      }
    },
    "schemas": {
      "TranscriptSegment": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "seg_01" },
          "speaker": { "type": "string", "example": "Abebe Kebede" },
          "speaker_id": { "type": "string", "example": "spk_01" },
          "start_time": { "type": "number", "format": "float", "example": 0.0, "description": "Segment start time in seconds." },
          "end_time": { "type": "number", "format": "float", "example": 6.4, "description": "Segment end time in seconds." },
          "text": { "type": "string", "example": "ሰላም ጤና ይስጥልኝ ወ/ሮ ትዕግስት፣ በሱቅዎ ውስጥ ዲጂታል ክፍያዎችን መጠቀም ከጀመሩ ምን ያህል ጊዜ ሆነዎት?", "description": "Verbatim native-language speech in UTF-8 Ge'ez or Latin script." },
          "translation": { "type": "string", "example": "Greetings Ms. Tigist, how long has it been since you began accepting digital payments in your shop?", "description": "Optional English translation alignment." },
          "confidence": { "type": "number", "format": "float", "example": 0.99, "description": "Acoustic confidence score between 0.00 and 1.00." }
        },
        "required": ["id", "speaker", "speaker_id", "start_time", "end_time", "text", "confidence"]
      },
      "EvidenceCitation": {
        "type": "object",
        "properties": {
          "start": { "type": "number", "format": "float", "example": 14.2, "description": "Exact audio timestamp start in seconds." },
          "end": { "type": "number", "format": "float", "example": 22.8, "description": "Exact audio timestamp end in seconds." },
          "speaker": { "type": "string", "example": "Tigist Haile" },
          "confidence": { "type": "number", "format": "float", "example": 0.98 },
          "text": { "type": "string", "example": "ደንበኞች በቴሌብር ለመክፈል ፍላጎት አላቸው፣ ነገር ግን አንዳንዴ ኔትወርክ ሲቋረጥ ክፍያው ዘግይቶ መድረሱ ያሳስበናል።" }
        },
        "required": ["start", "end", "speaker", "confidence", "text"]
      },
      "UsageMetrics": {
        "type": "object",
        "properties": {
          "audio_minutes": { "type": "number", "format": "float", "example": 0.71, "description": "Exact duration in decimal minutes." },
          "billed_minutes": { "type": "number", "format": "float", "example": 1.0, "description": "Duration billed in 1-second increments (15s minimum)." }
        },
        "required": ["audio_minutes", "billed_minutes"]
      },
      "TranscriptionCompletedResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "tra_01J8YV9X2KM04" },
          "status": { "type": "string", "enum": ["completed"], "example": "completed" },
          "language_detected": { "type": "string", "example": "am (99.4% confidence)" },
          "duration_seconds": { "type": "number", "format": "float", "example": 42.6 },
          "model": { "type": "string", "example": "andebet-speech-v1-enhanced" },
          "usage": { "$ref": "#/components/schemas/UsageMetrics" },
          "summary": { "type": "string", "example": "Merchant notes customers are eager to pay via mobile money but express concern over delayed SMS notifications during peak network congestion." },
          "evidence": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/EvidenceCitation" }
          },
          "subtitles": {
            "type": "object",
            "description": "Pre-formatted caption streams for direct video and media player integration.",
            "properties": {
              "srt": { "type": "string", "description": "Standard SubRip (.srt) subtitle track." },
              "vtt": { "type": "string", "description": "Standard WebVTT (.vtt) subtitle track." }
            }
          },
          "segments": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/TranscriptSegment" }
          }
        },
        "required": ["id", "status", "duration_seconds", "model", "usage", "segments"]
      },
      "TranscriptionQueuedResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "tra_01J9KW2X89LM02" },
          "status": { "type": "string", "enum": ["queued"], "example": "queued" },
          "estimated_duration_seconds": { "type": "integer", "example": 54 },
          "polling_url": { "type": "string", "example": "https://api.andebet.ai/v1/transcriptions/tra_01J9KW2X89LM02" },
          "webhook_registered": { "type": "boolean", "example": true },
          "created_at": { "type": "string", "format": "date-time", "example": "2026-10-12T14:30:00Z" }
        },
        "required": ["id", "status", "polling_url"]
      },
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "code": { "type": "string", "example": "invalid_api_key" },
          "message": { "type": "string", "example": "The provided API key is invalid or has been revoked." },
          "param": { "type": "string", "nullable": true, "example": null },
          "request_id": { "type": "string", "example": "req_01J8YV9ERR01" }
        },
        "required": ["code", "message", "request_id"]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "$ref": "#/components/schemas/ErrorEnvelope" }
        },
        "required": ["error"]
      }
    }
  }
}
