openapi: 3.1.0
info:
  title: Sulphur Caption API
  version: 1.0.0
  description: |
    Public API for creating caption jobs. Create a job, upload the raw video to
    the returned signed Storage URL, submit it, and poll for a terminal result.
    Internal website endpoints are intentionally excluded.
  contact:
    url: https://sulphur.dev/support?topic=api
externalDocs:
  description: Sulphur Caption API documentation
  url: https://api.sulphur.dev/
servers:
  - url: https://api.sulphur.dev
    description: Production
security:
  - SulphurApiKey: []
tags:
  - name: Captions
paths:
  /v1/caption:
    post:
      tags: [Captions]
      summary: Create a caption job
      description: |
        Reserves four credits and returns a signed upload URL. To retry safely,
        send the server-issued `idempotency_key` in the `Idempotency-Key` header
        with a body identical to the original request.
      operationId: createCaptionJob
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/RequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCaptionRequest'
      responses:
        '202':
          description: Job created or idempotently retrieved
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCaptionResponse'
        '400': { $ref: '#/components/responses/ApiError' }
        '401': { $ref: '#/components/responses/ApiError' }
        '402': { $ref: '#/components/responses/ApiError' }
        '403': { $ref: '#/components/responses/ApiError' }
        '404': { $ref: '#/components/responses/ApiError' }
        '409': { $ref: '#/components/responses/ApiError' }
        '413': { $ref: '#/components/responses/ApiError' }
        '422': { $ref: '#/components/responses/ApiError' }
        '429': { $ref: '#/components/responses/ApiError' }
        '5XX': { $ref: '#/components/responses/ApiError' }
    get:
      tags: [Captions]
      summary: List caption jobs
      operationId: listCaptionJobs
      parameters:
        - $ref: '#/components/parameters/RequestId'
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
          description: Maximum jobs returned.
        - name: cursor
          in: query
          schema: { type: string, minLength: 1, maxLength: 1000 }
          description: Opaque `next_cursor` from the previous page.
      responses:
        '200':
          description: Newest-first page of jobs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CaptionJobPage'
        '400': { $ref: '#/components/responses/ApiError' }
        '401': { $ref: '#/components/responses/ApiError' }
        '403': { $ref: '#/components/responses/ApiError' }
        '422': { $ref: '#/components/responses/ApiError' }
        '429': { $ref: '#/components/responses/ApiError' }
        '5XX': { $ref: '#/components/responses/ApiError' }
  /v1/caption/{job_id}:
    parameters:
      - $ref: '#/components/parameters/JobId'
      - $ref: '#/components/parameters/RequestId'
    get:
      tags: [Captions]
      summary: Get a caption job
      operationId: getCaptionJob
      responses:
        '200':
          description: Owned caption job
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CaptionJob'
        '401': { $ref: '#/components/responses/ApiError' }
        '403': { $ref: '#/components/responses/ApiError' }
        '404': { $ref: '#/components/responses/ApiError' }
        '429': { $ref: '#/components/responses/ApiError' }
    delete:
      tags: [Captions]
      summary: Cancel a waiting caption job
      description: |
        Cancels only `awaiting_upload` or `queued` jobs, refunds the four
        reserved credits, and removes temporary media. This does not permanently
        delete terminal job history.
      operationId: cancelCaptionJob
      responses:
        '200':
          description: Cancelled job
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CaptionJob'
        '401': { $ref: '#/components/responses/ApiError' }
        '403': { $ref: '#/components/responses/ApiError' }
        '404': { $ref: '#/components/responses/ApiError' }
        '409': { $ref: '#/components/responses/ApiError' }
        '429': { $ref: '#/components/responses/ApiError' }
  /v1/caption/{job_id}/submit:
    post:
      tags: [Captions]
      summary: Verify an upload and queue processing
      operationId: submitCaptionJob
      parameters:
        - $ref: '#/components/parameters/JobId'
        - $ref: '#/components/parameters/RequestId'
      responses:
        '202':
          description: Queued or current idempotent job state
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CaptionJob'
        '401': { $ref: '#/components/responses/ApiError' }
        '403': { $ref: '#/components/responses/ApiError' }
        '404': { $ref: '#/components/responses/ApiError' }
        '409': { $ref: '#/components/responses/ApiError' }
        '429': { $ref: '#/components/responses/ApiError' }
        '5XX': { $ref: '#/components/responses/ApiError' }
  /v1/caption/{job_id}/upload:
    put:
      deprecated: true
      tags: [Captions]
      summary: Deprecated application-server upload route
      description: Always returns `direct_upload_required`. Use the absolute signed `upload_url` returned by job creation.
      operationId: deprecatedCaptionUpload
      security: []
      parameters:
        - $ref: '#/components/parameters/JobId'
      responses:
        '410': { $ref: '#/components/responses/ApiError' }
components:
  securitySchemes:
    SulphurApiKey:
      type: http
      scheme: bearer
      bearerFormat: sk_sulphur
      description: Expiring server-side API key with caption:read and/or caption:write permission.
  parameters:
    JobId:
      name: job_id
      in: path
      required: true
      schema: { type: string, format: uuid }
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema: { type: string, minLength: 1, maxLength: 200 }
      description: Server-issued retry token from the original create response.
    RequestId:
      name: X-Request-ID
      in: header
      required: false
      schema: { type: string, minLength: 8, maxLength: 80, pattern: '^[A-Za-z0-9_-]+$' }
      description: Caller correlation ID echoed as X-Request-ID and in structured API errors.
  responses:
    ApiError:
      description: Structured API error
      headers:
        Retry-After:
          description: Delay in seconds before retrying a throttled request.
          schema: { type: integer, minimum: 1 }
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  schemas:
    CreateCaptionRequest:
      type: object
      additionalProperties: false
      required: [filename, content_type, size_bytes]
      properties:
        filename:
          type: string
          minLength: 1
          maxLength: 255
          examples: [example.mp4]
        content_type:
          $ref: '#/components/schemas/VideoContentType'
        size_bytes:
          type: integer
          minimum: 1
          maximum: 10485760
        webhook_url:
          type: [string, 'null']
          format: uri
          maxLength: 2048
          description: Reserved for a future release; production currently returns webhooks_unavailable.
        settings:
          oneOf:
            - $ref: '#/components/schemas/CaptionSettings'
            - type: 'null'
    CreateCaptionResponse:
      allOf:
        - $ref: '#/components/schemas/CaptionJob'
        - type: object
          required: [credits_remaining]
          properties:
            credits_remaining: { type: integer, minimum: 0 }
            upload_url:
              type: string
              format: uri
              description: Present while the job awaits upload.
            upload_method:
              type: string
              const: PUT
            upload_expires_at:
              type: string
              format: date-time
    CaptionJobPage:
      type: object
      additionalProperties: false
      required: [items, next_cursor]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/CaptionJob' }
        next_cursor:
          type: [string, 'null']
    CaptionJob:
      type: object
      additionalProperties: false
      required:
        - id
        - status
        - filename
        - content_type
        - size_bytes
        - queue_class
        - idempotency_key
        - settings
        - caption
        - error
        - created_at
        - submitted_at
        - started_at
        - completed_at
      properties:
        id: { type: string, format: uuid }
        status:
          type: string
          enum: [awaiting_upload, queued, processing, completed, failed, expired, cancelled]
        filename: { type: string }
        content_type:
          oneOf:
            - $ref: '#/components/schemas/VideoContentType'
            - type: 'null'
        size_bytes: { type: integer, minimum: 1, maximum: 10485760 }
        queue_class: { type: string, enum: [interactive, batch] }
        idempotency_key: { type: [string, 'null'] }
        settings: { $ref: '#/components/schemas/CaptionSettingsResolved' }
        caption: { type: [string, 'null'] }
        error: { type: [string, 'null'] }
        created_at: { type: string, format: date-time }
        submitted_at: { type: [string, 'null'], format: date-time }
        started_at: { type: [string, 'null'], format: date-time }
        completed_at: { type: [string, 'null'], format: date-time }
    CaptionSettings:
      type: object
      additionalProperties: false
      properties:
        caption_length: { type: string, enum: [very small, small, medium, large, very large] }
        include_watermark_info: { type: boolean }
        has_thinking: { type: boolean }
        vulgarity: { $ref: '#/components/schemas/Level' }
        uncertainty: { $ref: '#/components/schemas/Level' }
        character_names: { type: string, enum: [none, ambiguous, single, multiple] }
        fluff: { $ref: '#/components/schemas/Level' }
        has_repetition: { type: boolean }
        speculation: { $ref: '#/components/schemas/Level' }
        temporal_detail: { type: string, enum: [static, low, medium, high] }
        visual_specificity: { type: string, enum: [generic, moderate, detailed, excessive] }
        camera_detail: { $ref: '#/components/schemas/Level' }
        caption_style: { type: string, enum: [plain, verbose, ornate, robotic] }
    CaptionSettingsResolved:
      allOf:
        - $ref: '#/components/schemas/CaptionSettings'
        - type: object
          required:
            - caption_length
            - include_watermark_info
            - has_thinking
            - vulgarity
            - uncertainty
            - character_names
            - fluff
            - has_repetition
            - speculation
            - temporal_detail
            - visual_specificity
            - camera_detail
            - caption_style
    Level:
      type: string
      enum: [none, low, medium, high]
    VideoContentType:
      type: string
      enum:
        - video/mp4
        - video/quicktime
        - video/3gpp
        - video/3gpp2
        - video/webm
        - video/x-matroska
        - video/x-msvideo
        - video/mpeg
        - video/ogg
        - video/x-flv
    ApiError:
      type: object
      additionalProperties: false
      required: [error]
      properties:
        error:
          type: object
          additionalProperties: false
          required: [code, message, request_id]
          properties:
            code: { type: string }
            message: { type: string }
            request_id: { type: string }
