{
  "openapi": "3.0.0",
  "info": {
    "title": "Treza Pipelines API",
    "description": "Treza builds video pipelines from a description. Build pipelines that chain the best AI models (Veo 3.1, Sora 2, Gemini Image, Llama, and any open model) with voiceover, captions, sequencing, and publishing, then call any published pipeline as an API.\n\nTwo ways to call a published pipeline:\n- Typed invoke: POST /api/pipelines/{id}/invoke with JSON inputs matching the pipeline's input contract. Returns a runId (HTTP 202); poll GET /api/pipelines/{id}/invoke?runId=... for status and outputs.\n- OpenAI-compatible: POST /api/pipelines/{id}/chat/completions works as a drop-in for any OpenAI SDK, streaming included. The latest user message feeds the pipeline and the output returns as the assistant message.\n\nAuthentication uses scoped API keys (Bearer treza_live_...) created in the Treza platform. The key must own the pipeline and the pipeline must be published. Billing is prepaid credits that work across every model.\n\nAn MCP server is also available at https://www.trezalabs.com/api/mcp (streamable HTTP, OAuth 2.1) exposing tools to list pipelines, inspect runs, and trigger new runs.",
    "version": "3.0.0",
    "contact": {
      "name": "Treza Support",
      "url": "https://www.trezalabs.com/support",
      "email": "hello@trezalabs.com"
    }
  },
  "servers": [
    {
      "url": "https://www.trezalabs.com",
      "description": "Production"
    }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/api/pipelines/{id}/invoke": {
      "post": {
        "operationId": "invokePipeline",
        "summary": "Invoke a published pipeline",
        "description": "Starts a run of the deployed pipeline snapshot with the given inputs. Returns a runId immediately; poll the GET variant of this path for status and outputs.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Pipeline id",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "inputs": {
                    "type": "object",
                    "description": "Values keyed by the pipeline's input contract",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Run accepted",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RunAccepted" }
              }
            }
          },
          "401": { "description": "Missing or invalid API key" },
          "403": { "description": "Key does not own this pipeline" },
          "404": { "description": "Pipeline not found" },
          "409": { "description": "Pipeline is not published" }
        }
      },
      "get": {
        "operationId": "getInvokeRunStatus",
        "summary": "Poll a pipeline run",
        "description": "Returns the status of a run started via invoke, including outputs once the run completes.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Pipeline id",
            "schema": { "type": "string" }
          },
          {
            "name": "runId",
            "in": "query",
            "required": true,
            "description": "Run id returned by the invoke call",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Run status",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RunStatus" }
              }
            }
          },
          "401": { "description": "Missing or invalid API key" },
          "404": { "description": "Run not found" }
        }
      }
    },
    "/api/pipelines/{id}/chat/completions": {
      "post": {
        "operationId": "pipelineChatCompletions",
        "summary": "OpenAI-compatible pipeline endpoint",
        "description": "Drop-in replacement for the OpenAI chat completions API. Point any OpenAI SDK at this base URL with a Treza API key. The latest user message is fed into the pipeline and the pipeline output is returned as the assistant message. Supports streaming via server-sent events.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Pipeline id",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["messages"],
                "properties": {
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "role": { "type": "string" },
                        "content": { "type": "string" }
                      }
                    }
                  },
                  "stream": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Chat completion (JSON, or SSE when stream is true)" },
          "401": { "description": "Missing or invalid API key" },
          "403": { "description": "Key does not own this pipeline" },
          "404": { "description": "Pipeline not found" },
          "409": { "description": "Pipeline is not published" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Scoped API key created in the Treza platform (treza_live_...)"
      }
    },
    "schemas": {
      "RunAccepted": {
        "type": "object",
        "properties": {
          "runId": { "type": "string" },
          "status": { "type": "string", "example": "running" }
        }
      },
      "RunStatus": {
        "type": "object",
        "properties": {
          "runId": { "type": "string" },
          "status": {
            "type": "string",
            "description": "running, succeeded, failed, or cancelled"
          },
          "outputs": {
            "type": "object",
            "description": "Values keyed by the pipeline's output contract, present once the run succeeds. Media outputs are returned as URLs.",
            "additionalProperties": true
          },
          "error": { "type": "string" }
        }
      }
    }
  }
}
