{
  "openapi": "3.1.0",
  "info": {
    "title": "Polarity Transcribe API",
    "version": "1.0.0",
    "description": "Transcribes audio recordings (calls, meetings, voice messages) into speaker-labeled text with Amazon Bedrock Data Automation. Nothing is kept: the uploaded audio is deleted as soon as the transcript is ready, and the transcript itself can be read for 10 minutes, then it is deleted.\n\n## Flow\n\n1. `POST /jobs` with the file name and the spoken languages. The answer has a `jobId` and a presigned upload URL.\n2. `PUT` the audio bytes to `upload.url` within one hour. No header is needed, and no API key: the URL is already signed.\n3. `GET /jobs/{jobId}` every 5 to 10 seconds until `status` is `COMPLETED` or `FAILED`. Processing takes from about 40 seconds to several minutes.\n4. Read `transcript` from the `COMPLETED` answer. It stays readable until `expiresAt` (10 minutes), then the job is deleted and `GET` answers `404`.\n5. Optionally `DELETE /jobs/{jobId}` to delete it right away.\n\nA job that never completes (no upload, client gone) is deleted 4 hours after its creation.\n\n## Authentication\n\nEvery `/jobs` request needs the header `x-api-key`. Polarity team: 1Password, vault Shared, item \"Transcribe API key\". Without it, or with a wrong one, the answer is `403`. This page and `/openapi.json` are public.\n\n## Languages\n\nThe spoken language is always forced, because automatic detection turns Italian into English-looking nonsense. Default `[\"IT\"]`; use `[\"EN\"]` for English and `[\"IT\", \"EN\"]` for calls that switch language. If an Italian transcript still looks garbled, `transcript.warnings` says so: retry with the right `languages`.\n\n## Limits\n\n| | |\n| --- | --- |\n| Audio | 2 hours, 2 GB; `.wav .mp3 .ogg .flac .amr .webm .m4a` |\n| Rate | 10 requests/s (burst 20), 20,000 requests/day per key |\n\n## Example\n\n```sh\nAPI=https://transcribe.polarity.dev\nKEY=$(op read 'op://Shared/Transcribe API key/credential' --account sfsrl.1password.com)\n\nJOB=$(curl -s -X POST \"$API/jobs\" -H \"x-api-key: $KEY\" \\\n  -d '{\"filename\": \"call.m4a\", \"languages\": [\"IT\"]}')\ncurl -s -T call.m4a \"$(echo \"$JOB\" | jq -r .upload.url)\"\n\n# repeat until COMPLETED\ncurl -s \"$API/jobs/$(echo \"$JOB\" | jq -r .jobId)\" -H \"x-api-key: $KEY\" | jq -r .transcript.markdown\n```\n\nThe repository `polarity-dev/transcribe-api` has a ready client, `scripts/transcribe.py` (Python standard library only)."
  },
  "servers": [
    {
      "url": "https://transcribe.polarity.dev"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Jobs",
      "description": "Transcription jobs"
    },
    {
      "name": "Documentation",
      "description": "This documentation and the OpenAPI definition"
    }
  ],
  "paths": {
    "/jobs": {
      "post": {
        "tags": [
          "Jobs"
        ],
        "operationId": "createJob",
        "summary": "Create a transcription job",
        "description": "Creates the job and returns a presigned URL to `PUT` the audio to. Transcription starts by itself when the upload completes.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateJobRequest"
              },
              "example": {
                "filename": "call-cliente.m4a",
                "languages": [
                  "IT"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Job created, waiting for the upload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedJob"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/jobs/{jobId}": {
      "parameters": [
        {
          "name": "jobId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "tags": [
          "Jobs"
        ],
        "operationId": "getJob",
        "summary": "Get the job status, and the transcript once ready",
        "description": "Poll every 5 to 10 seconds. When `status` is `COMPLETED` the answer contains `transcript`, readable until `expiresAt`.",
        "responses": {
          "200": {
            "description": "Current state of the job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "Jobs"
        ],
        "operationId": "deleteJob",
        "summary": "Delete the job and all its data now",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/": {
      "get": {
        "tags": [
          "Documentation"
        ],
        "operationId": "getDocs",
        "summary": "This documentation",
        "security": [],
        "responses": {
          "200": {
            "description": "HTML page",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": [
          "Documentation"
        ],
        "operationId": "getOpenApi",
        "summary": "OpenAPI definition of this API",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request (missing file name, unsupported format or language)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "unsupported audio format .pdf; supported: .wav, .mp3, .ogg, .flac, .amr, .webm, .m4a"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Missing or invalid API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "missing or invalid x-api-key header"
            }
          }
        }
      },
      "NotFound": {
        "description": "The job does not exist or has expired",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "job not found or expired"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Rate or daily quota exceeded",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Language": {
        "type": "string",
        "enum": [
          "IT",
          "EN"
        ],
        "description": "Spoken language. Codes are case-insensitive."
      },
      "CreateJobRequest": {
        "type": "object",
        "required": [
          "filename"
        ],
        "properties": {
          "filename": {
            "type": "string",
            "maxLength": 200,
            "description": "Name of the audio file. The extension sets the format; the name without extension becomes the transcript title.",
            "examples": [
              "call-cliente.m4a"
            ]
          },
          "languages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Language"
            },
            "minItems": 1,
            "default": [
              "IT"
            ],
            "description": "Spoken languages: `[\"IT\"]`, `[\"EN\"]` or `[\"IT\", \"EN\"]`."
          }
        }
      },
      "Status": {
        "type": "string",
        "enum": [
          "UPLOAD_PENDING",
          "PROCESSING",
          "COMPLETED",
          "FAILED"
        ]
      },
      "Job": {
        "type": "object",
        "required": [
          "jobId",
          "status",
          "filename",
          "languages",
          "createdAt",
          "expiresAt"
        ],
        "properties": {
          "jobId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "filename": {
            "type": "string"
          },
          "languages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Language"
            }
          },
          "createdAt": {
            "type": "integer",
            "description": "Unix time, seconds"
          },
          "expiresAt": {
            "type": "integer",
            "description": "Unix time, seconds: after this the job and its data are deleted"
          },
          "error": {
            "type": "string",
            "description": "Why the job failed, only when `status` is `FAILED`"
          },
          "transcript": {
            "$ref": "#/components/schemas/Transcript"
          }
        }
      },
      "CreatedJob": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Job"
          },
          {
            "type": "object",
            "required": [
              "upload"
            ],
            "properties": {
              "upload": {
                "type": "object",
                "required": [
                  "method",
                  "url",
                  "expiresAt"
                ],
                "properties": {
                  "method": {
                    "type": "string",
                    "const": "PUT"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Presigned S3 URL: send the audio bytes as the request body"
                  },
                  "expiresAt": {
                    "type": "integer",
                    "description": "Unix time, seconds"
                  }
                }
              }
            }
          }
        ]
      },
      "Transcript": {
        "type": "object",
        "description": "Only when `status` is `COMPLETED`",
        "required": [
          "markdown",
          "turns",
          "warnings"
        ],
        "properties": {
          "markdown": {
            "type": "string",
            "description": "Title, language and one `**spk_N:** text` block per turn",
            "examples": [
              "# call-cliente\n\n> Transcript (language: IT)\n\n**spk_0:** Buongiorno, ...\n\n**spk_1:** Buongiorno.\n"
            ]
          },
          "turns": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Turn"
            }
          },
          "durationMs": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Length of the audio"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Turn": {
        "type": "object",
        "description": "Consecutive speech of one speaker",
        "required": [
          "speaker",
          "text"
        ],
        "properties": {
          "speaker": {
            "type": "string",
            "description": "Speaker label (`spk_0`, `spk_1`, ...), not a name",
            "examples": [
              "spk_0"
            ]
          },
          "text": {
            "type": "string"
          },
          "startMs": {
            "type": [
              "integer",
              "null"
            ]
          },
          "endMs": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}