{
  "openapi": "3.1.0",
  "info": {
    "title": "WAVE Runtime",
    "version": "0.1.0",
    "description": "OpenAI-compatible chat completions proxy routed through WAVE gateway dispatch. Supports streaming (SSE), tool calling with cap enforcement, and automatic usage embedding. Authentication is gateway-trust: a Bearer token validated upstream; no user-level keys."
  },
  "servers": [
    {
      "url": "https://runtime.wave.online",
      "description": "Production"
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "operationId": "chatCompletions",
        "summary": "Chat completions (OpenAI-compatible)",
        "description": "Proxies to the WAVE gateway dispatch route. Always streams (stream: true forced server-side). max_completion_tokens is clamped to ≤ 4096 to prevent context-budget exhaustion. Usage is embedded on the finish chunk (x-wave-usage) so clients that only read choice-carrying chunks still capture token counts. Tool descriptions are capped at 200 chars; system-reminder payloads containing available_skills are stripped to a safe fallback.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Streaming SSE response. Each data line is a chat.completion.chunk object. The finish chunk carries usage data; the final event is data: [DONE].",
            "content": {
              "text/event-stream": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionChunk"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionChunk"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/": {
      "get": {
        "operationId": "landingPage",
        "summary": "Branded landing page",
        "description": "WAVE Runtime public landing page served by the spoke chassis.",
        "responses": {
          "200": {
            "description": "HTML landing page.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "openapiDoc",
        "summary": "OpenAPI 3.1 contract (this document)",
        "description": "Returns this OpenAPI document as JSON. The contract IS the product.",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 JSON document.",
            "content": {
              "application/json": {}
            }
          }
        }
      }
    },
    "/mcp": {
      "get": {
        "operationId": "mcpCapabilities",
        "summary": "MCP capabilities declaration",
        "description": "Open MCP capabilities (JSON-RPC init response). No auth required.",
        "responses": {
          "200": {
            "description": "MCP server capabilities.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "mcpStreamableHttp",
        "summary": "MCP streamable-http endpoint",
        "description": "JSON-RPC over POST, gateway-trust gated on tool calls.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List available models",
        "responses": {
          "200": {
            "description": "Model list.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/transcribe": {
      "post": {
        "operationId": "transcribe",
        "summary": "Transcribe audio (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/transcribe with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transcription result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/captions": {
      "post": {
        "operationId": "captions",
        "summary": "Generate captions (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/captions with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Captions result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/voice": {
      "post": {
        "operationId": "voice",
        "summary": "Voice synthesis (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/voice with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Voice synthesis result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/vision": {
      "post": {
        "operationId": "vision",
        "summary": "Vision analysis (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/vision with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Vision analysis result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/render": {
      "post": {
        "operationId": "render",
        "summary": "Render output (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/render with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Render result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/transcode": {
      "post": {
        "operationId": "transcode",
        "summary": "Transcode media (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/transcode with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transcode result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/v1/mux": {
      "post": {
        "operationId": "mux",
        "summary": "Multiplex streams (capability-hop passthrough)",
        "description": "POST body streamed to the WAVE gateway at /v1/mux with customer-key auth.",
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Mux result from gateway."
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Gateway-trust Bearer token. Validated by the WAVE gateway; the spoke forwards it as-is. Set via WAVE_GATEWAY_API_KEY on the worker or pass an Authorization header from the client."
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model identifier (e.g. qwen2.5:3b)."
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            },
            "description": "Conversation messages."
          },
          "stream": {
            "type": "boolean",
            "default": true,
            "description": "Always forced to true server-side. Included for client compatibility."
          },
          "max_tokens": {
            "type": "integer",
            "default": 1024,
            "description": "Maximum tokens in the completion. Default 1024 if omitted."
          },
          "max_completion_tokens": {
            "type": "integer",
            "description": "Maximum completion tokens (newer field). Clamped server-side to ≤ 4096 to prevent context-budget exhaustion. Values above 4096 are silently reduced."
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Tool definitions. Descriptions longer than 200 chars are truncated. Pass x-wave-strip-tools: 1 header to remove all tools before proxying."
          },
          "stream_options": {
            "type": "object",
            "properties": {
              "include_usage": {
                "type": "boolean",
                "default": true
              }
            },
            "description": "Stream options. include_usage is forced true server-side."
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant",
              "tool"
            ]
          },
          "content": {
            "type": "string"
          }
        }
      },
      "ChatCompletionChunk": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "enum": [
              "chat.completion.chunk"
            ]
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChunkChoice"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage",
            "description": "Present on the finish chunk (x-wave-usage) AND as a separate trailing event."
          }
        }
      },
      "ChunkChoice": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "delta": {
            "type": "object"
          },
          "finish_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "stop",
              "length",
              "tool_calls",
              null
            ]
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          }
        }
      },
      "ModelList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "object": {
                  "type": "string",
                  "enum": [
                    "model"
                  ]
                },
                "owned_by": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}