{
  "openapi": "3.1.0",
  "info": {
    "title": "Transcript API",
    "version": "0.3.0",
    "description": "Upload eligible media once, save private job access, authorize payment within a spending limit and retrieve English plain text. The file helper supports native payment credentials and same-job recovery."
  },
  "servers": [
    {
      "url": "https://api.getaira.io"
    }
  ],
  "paths": {
    "/v1/transcriptions": {
      "post": {
        "operationId": "quoteRecording",
        "description": "Maximum 24,000,000 bytes and 120 minutes including encoding padding. MP3, PCM16 WAV or nonfragmented MP4/M4A with one AAC-LC track. An HTTPS URL must directly serve an eligible S3/R2 object without redirects. Save a random Idempotency-Key before upload; interrupted intake retries use that same key and identical input. After receiving a job, use its /pay continuation.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          },
          {
            "name": "Accept-Payment",
            "in": "header",
            "required": false,
            "description": "Native payment-method negotiation. The downloadable client's --native option sets this header for the supported payment method.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "media_url"
                ],
                "additionalProperties": false,
                "properties": {
                  "media_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            },
            "headers": {
              "Payment-Receipt": {
                "description": "Optional native settlement receipt. Keep it with the same private job; it does not replace job access.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "202": {
            "description": "Pending or held job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            },
            "headers": {
              "Payment-Receipt": {
                "description": "Optional native settlement receipt. Keep it with the same private job; it does not replace job access.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "402": {
            "description": "Save the quote and private access before authorizing payment. Native clients receive a signed payment challenge; browser clients receive a checkout link. Continue the same private job without another upload.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Native payment challenge. Validate its API realm, job, amount, currency and expiry before obtaining a wallet credential.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          },
          "default": {
            "description": "Structured error. Retain the same job or pending intake receipt when its outcome is unresolved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/transcriptions/jobs/{id}/pay": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^job_[a-f0-9]{32}$"
          }
        }
      ],
      "post": {
        "operationId": "continuePayment",
        "security": [
          {
            "jobAccess": []
          },
          {
            "jobToken": []
          },
          {
            "jobToken": [],
            "paymentAuthorization": []
          }
        ],
        "description": "Native clients send X-Job-Token and the signed Payment authorization. An unpaid native request receives a challenge. Browser clients use bearer access to verify checkout. Persist authorization before sending; retries use the same credential and job. Settlement starts transcription once. No media body.",
        "parameters": [
          {
            "name": "Accept-Payment",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Completed job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            },
            "headers": {
              "Payment-Receipt": {
                "description": "Optional native settlement receipt. Keep it with the same private job; it does not replace job access.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "202": {
            "description": "Pending or held job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            },
            "headers": {
              "Payment-Receipt": {
                "description": "Optional native settlement receipt. Keep it with the same private job; it does not replace job access.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "402": {
            "description": "Save the quote and private access before authorizing payment. Native clients receive a signed payment challenge; browser clients receive a checkout link. Continue the same private job without another upload.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Native payment challenge. Validate its API realm, job, amount, currency and expiry before obtaining a wallet credential.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentRequired"
                }
              }
            }
          },
          "default": {
            "description": "Structured error. Retain the same job or pending intake receipt when its outcome is unresolved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/transcriptions/jobs/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^job_[a-f0-9]{32}$"
          }
        }
      ],
      "get": {
        "operationId": "transcriptStatus",
        "security": [
          {
            "jobAccess": []
          }
        ],
        "description": "Poll no more than once every 15 seconds. Resume a saved native authorization at POST /pay. A paid job resumes its existing processing. Held jobs require support; do not create replacement purchases.",
        "responses": {
          "200": {
            "description": "Completed job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "202": {
            "description": "Pending or held job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "default": {
            "description": "Structured error. Retain the same job or pending intake receipt when its outcome is unresolved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/transcriptions/jobs/{id}/result": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^job_[a-f0-9]{32}$"
          }
        }
      ],
      "get": {
        "operationId": "downloadTranscript",
        "security": [
          {
            "jobAccess": []
          }
        ],
        "description": "Authenticated paid completed job only. Private no-store JSON. Download before result_expires_at; the deadline is set when the quote is created, rather than when processing finishes.",
        "responses": {
          "200": {
            "description": "Private transcript",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Result"
                }
              }
            }
          },
          "default": {
            "description": "Structured error. Retain the same job or pending intake receipt when its outcome is unresolved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "jobAccess": {
        "type": "http",
        "scheme": "bearer",
        "description": "Private per-job access_token returned at intake and bound retries. Save privately before payment; never put it in a URL."
      },
      "jobToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Job-Token",
        "description": "The same saved access_token, sent separately from a native Payment authorization."
      },
      "paymentAuthorization": {
        "type": "http",
        "scheme": "Payment",
        "description": "A wallet-authorized credential created from the accepted native challenge. Save it privately before sending. Reuse it on uncertain retries."
      }
    },
    "schemas": {
      "Quote": {
        "type": "object",
        "required": [
          "amount_cents",
          "currency",
          "price_version",
          "expires_at"
        ],
        "properties": {
          "amount_cents": {
            "type": "integer",
            "minimum": 50
          },
          "currency": {
            "const": "usd"
          },
          "price_version": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Job": {
        "type": "object",
        "required": [
          "job_id",
          "state",
          "quote",
          "result_expires_at"
        ],
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^job_[a-f0-9]{32}$"
          },
          "state": {
            "type": "string",
            "enum": [
              "quoted",
              "paid",
              "provider_started",
              "provider_pending",
              "completed",
              "reconciliation_required",
              "refund_required",
              "refunded"
            ]
          },
          "quote": {
            "$ref": "#/components/schemas/Quote"
          },
          "result_expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "result": {
            "type": "object",
            "properties": {
              "format": {
                "const": "text"
              },
              "characters": {
                "type": "integer"
              },
              "result_path": {
                "type": "string"
              }
            }
          }
        }
      },
      "PaymentRequired": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Job"
          },
          {
            "type": "object",
            "required": [
              "access_token",
              "status",
              "payment"
            ],
            "properties": {
              "access_token": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{43}$"
              },
              "status": {
                "const": "payment_required"
              },
              "payment": {
                "type": "object",
                "required": [
                  "method",
                  "mode",
                  "continuation_path"
                ],
                "properties": {
                  "method": {
                    "type": "string",
                    "description": "Payment method returned for this job. Treat this identifier as opaque."
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "test",
                      "live"
                    ]
                  },
                  "checkout_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "retry": {
                    "type": "string",
                    "description": "Native payment continuation instructions. Retain the same credential and do not upload media again."
                  },
                  "continuation_path": {
                    "type": "string"
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "checkout_url"
                    ]
                  },
                  {
                    "required": [
                      "retry"
                    ],
                    "not": {
                      "required": [
                        "checkout_url"
                      ]
                    }
                  }
                ]
              }
            }
          }
        ]
      },
      "Result": {
        "type": "object",
        "required": [
          "job_id",
          "text"
        ],
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^job_[a-f0-9]{32}$"
          },
          "text": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code"
            ],
            "properties": {
              "code": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
