{
  "openapi": "3.0.3",
  "info": {
    "title": "PlayHT API",
    "version": "1.0.0",
    "description": "Generate speech, dialogue, sound effects, music, and more. All endpoints are asynchronous: a submission call returns a task immediately, and you poll for completion. There is no outbound webhook yet — see the note on GET /tts-job/{jobId} for the recommended polling pattern."
  },
  "servers": [{ "url": "/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pk_live_...",
        "description": "Create a key at /app/api-keys. Send it as: Authorization: Bearer pk_live_..."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "example": "insufficient_credits" },
          "message": { "type": "string", "example": "You have no credits remaining this month. Please upgrade your plan." }
        }
      },
      "VendorTaskResponse": {
        "type": "object",
        "description": "Wraps the vendor's response. `body.status` is a vendor-defined string (commonly queued/processing/done/failed) — poll GET /task/{prefixedId} or GET /tts-job/{jobId} until it reaches a terminal state.",
        "properties": {
          "status": { "type": "integer", "description": "Upstream HTTP status code" },
          "body": {
            "type": "object",
            "properties": {
              "task_id": { "type": "string", "example": "t1_a1b2c3", "description": "Opaque, vendor-neutral task id — always prefixed t1_ or t2_, never a raw vendor id" },
              "status": { "type": "string" },
              "audio_url": { "type": "string", "description": "Present once complete — always same-origin (proxied), never a vendor URL" }
            }
          }
        }
      }
    },
    "parameters": {
      "voiceId": {
        "name": "voice_id", "in": "query", "schema": { "type": "string" },
        "description": "Canonical voice id from GET /voices, or a cloned-voice id when voice_source=clone"
      }
    },
    "responses": {
      "Unauthenticated": {
        "description": "Missing, invalid, expired, or revoked API key",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "InsufficientCredits": {
        "description": "Not enough credits, or a team spending limit was hit",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "TooManyRequests": {
        "description": "Rate limit (120 requests/minute per API key) or plan concurrency limit exceeded",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "ServiceUnavailable": {
        "description": "The selected vendor is at capacity or the tool is disabled",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "ValidationError": {
        "description": "Request failed validation",
        "content": { "application/json": { "schema": { "type": "object", "properties": { "message": { "type": "string" }, "errors": { "type": "object" } } } } }
      }
    }
  },
  "paths": {
    "/voices": {
      "get": {
        "summary": "List available voices",
        "description": "Pass source=clone to list only your own cloned voices instead of the shared catalog.",
        "parameters": [
          { "name": "source", "in": "query", "schema": { "type": "string", "enum": ["signature", "natural", "quick", "compact", "playht", "clone"] } },
          { "name": "provider", "in": "query", "schema": { "type": "string", "enum": ["elevenlabs", "minimax", "edge", "kokoro", "playht", "clone"] }, "description": "Deprecated alias for source." },
          { "name": "language", "in": "query", "schema": { "type": "string" } },
          { "name": "gender", "in": "query", "schema": { "type": "string" } },
          { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "Free-text search (supported for some providers only)" },
          { "name": "age", "in": "query", "schema": { "type": "string" } },
          { "name": "accent", "in": "query", "schema": { "type": "string" } },
          { "name": "use_case", "in": "query", "schema": { "type": "string" } },
          { "name": "page", "in": "query", "schema": { "type": "integer" } },
          { "name": "page_size", "in": "query", "schema": { "type": "integer" } }
        ],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" }
        }
      }
    },
    "/tts": {
      "post": {
        "summary": "Text to speech",
        "description": "Charges credits (see plan pricing). Submits asynchronously — poll the returned task_id via GET /tts-job/{jobId} or GET /task/{prefixedId}.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": { "type": "string", "description": "Required unless ssml is given. Max length is plan-configurable (default 5000)." },
                  "ssml": { "type": "string", "description": "Required unless text is given. Max 10000 chars." },
                  "voice_id": { "type": "string" },
                  "voice_source": { "type": "string", "enum": ["signature", "natural", "quick", "compact", "playht", "clone"] },
                  "provider_brand": { "type": "string", "enum": ["elevenlabs", "minimax", "edge", "kokoro", "playht", "clone"], "description": "Deprecated alias for voice_source." },
                  "output_format": { "type": "string", "enum": ["mp3", "wav", "ogg", "flac"] },
                  "stability": { "type": "number", "minimum": 0, "maximum": 1 },
                  "similarity_boost": { "type": "number", "minimum": 0, "maximum": 1 },
                  "speed": { "type": "number", "minimum": 0.5, "maximum": 2 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/dialogue": {
      "post": {
        "summary": "Multi-speaker dialogue",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["speakers", "inputs"],
                "properties": {
                  "speakers": {
                    "type": "array", "minItems": 1,
                    "items": { "type": "object", "required": ["name"], "properties": { "name": { "type": "string" }, "voice_id": { "type": "string" } } }
                  },
                  "inputs": {
                    "type": "array", "minItems": 1,
                    "items": { "type": "object", "required": ["speaker", "text"], "properties": { "speaker": { "type": "string" }, "text": { "type": "string" } } }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/voice-changer": {
      "post": {
        "summary": "Convert an audio file to a target voice",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "audio": { "type": "string", "format": "binary", "description": "Field name is 'audio' or 'file' depending on which vendor is routed — send either." },
                  "file": { "type": "string", "format": "binary" },
                  "voice_id": { "type": "string" },
                  "voice_source": { "type": "string", "enum": ["signature", "natural", "quick", "compact", "playht"] },
                  "provider_brand": { "type": "string", "enum": ["elevenlabs", "minimax", "edge", "kokoro", "playht"], "description": "Deprecated alias for voice_source." },
                  "model_id": { "type": "string" },
                  "remove_background_noise": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/dubbing": {
      "post": {
        "summary": "Dub an audio/video file into another language",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["target_lang"],
                "properties": {
                  "target_lang": { "type": "string", "maxLength": 10 },
                  "source_lang": { "type": "string", "maxLength": 10 },
                  "num_speakers": { "type": "integer", "minimum": 0, "maximum": 20 },
                  "file": { "type": "string", "format": "binary" },
                  "disable_voice_cloning": { "type": "boolean" },
                  "start_time": { "type": "number" },
                  "end_time": { "type": "number" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/sfx": {
      "post": {
        "summary": "Generate a sound effect from a text prompt",
        "description": "Availability depends on internal routing — this endpoint may return 503 tool_unavailable if temporarily disabled.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["text"],
                "properties": {
                  "text": { "type": "string", "description": "Max length is plan-configurable (default 300)" },
                  "duration_seconds": { "type": "number", "minimum": 0.5 },
                  "prompt_influence": { "type": "number", "minimum": 0, "maximum": 1 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/music": {
      "post": {
        "summary": "Generate music from a text prompt",
        "description": "Availability depends on internal routing — this endpoint may return 503 tool_unavailable if temporarily disabled.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt"],
                "properties": {
                  "prompt": { "type": "string", "description": "Max length is plan-configurable (default 500)" },
                  "duration_seconds": { "type": "number", "minimum": 5 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/stt": {
      "post": {
        "summary": "Speech to text (transcription)",
        "description": "Availability depends on internal routing — this endpoint may return 503 tool_unavailable if temporarily disabled.",
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": { "type": "string", "format": "binary" },
                  "language": { "type": "string", "maxLength": 10 },
                  "diarize": { "type": "boolean" },
                  "smart_format": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/voice-isolate": {
      "post": {
        "summary": "Isolate voice from background noise",
        "description": "Availability depends on internal routing — this endpoint may return 503 tool_unavailable if temporarily disabled.",
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": { "type": "object", "properties": { "file": { "type": "string", "format": "binary" } } }
            }
          }
        },
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/task/{prefixedId}": {
      "get": {
        "summary": "Poll raw vendor task status",
        "description": "Returns the vendor's response body as-is (sanitized). You may only poll tasks your own API key created.",
        "parameters": [{ "name": "prefixedId", "in": "path", "required": true, "schema": { "type": "string" }, "example": "t1_a1b2c3" }],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "description": "This task was not created by your API key" }
        }
      }
    },
    "/tts-poll/{prefixedId}": {
      "get": {
        "summary": "Poll a single-chunk TTS task and finalize it on completion",
        "description": "Prefer GET /tts-job/{jobId} for new integrations — this endpoint only covers the single-chunk TTS path.",
        "parameters": [{ "name": "prefixedId", "in": "path", "required": true, "schema": { "type": "string" }, "example": "t1_a1b2c3" }],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VendorTaskResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "403": { "description": "This task was not created by your API key" }
        }
      }
    },
    "/tts-job/{jobId}": {
      "get": {
        "summary": "Poll a TTS job (recommended)",
        "description": "Covers both single-chunk and long-text chunked jobs uniformly. Poll this until status is 'complete' or 'failed'. There is currently no outbound webhook for job completion — polling is the only notification mechanism.",
        "parameters": [{ "name": "jobId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "enum": ["processing", "merging", "complete", "failed"] },
                    "audio_url": { "type": "string" },
                    "total_chunks": { "type": "integer" },
                    "completed_chunks": { "type": "integer" },
                    "error": { "type": "string" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthenticated" },
          "404": { "description": "No job with this id owned by your account" }
        }
      }
    }
  }
}
