{
  "openapi": "3.1.0",
  "info": {
    "title": "VERBAREX API",
    "version": "1.0.0",
    "description": "Production API for VERBAREX AI Gateway (1M context reasoning inference) and Cloud Sandboxes (hardware-isolated Linux microVM execution)."
  },
  "servers": [{"url": "https://verbarex.com/api/v1"}],
  "security": [{"bearerAuth": []}],
  "paths": {
    "/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List active AI models",
        "responses": {
          "200": {
            "description": "Active model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {"$ref": "#/components/schemas/Model"}
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create chat completion (OpenAI-compatible)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/ChatCompletionRequest"}
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion response or SSE stream",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ChatCompletionResponse"}
              },
              "text/event-stream": {
                "schema": {"type": "string"}
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "402": {"$ref": "#/components/responses/ApiError"},
          "403": {"$ref": "#/components/responses/ApiError"},
          "422": {"$ref": "#/components/responses/ApiError"},
          "429": {"$ref": "#/components/responses/ApiError"},
          "503": {"$ref": "#/components/responses/ApiError"}
        }
      }
    },
    "/workspaces": {
      "get": {
        "operationId": "listWorkspaces",
        "summary": "List active Cloud Sandbox microVMs",
        "responses": {
          "200": {
            "description": "List of sandboxes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {"$ref": "#/components/schemas/Workspace"}
                    }
                  }
                }
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"}
        }
      },
      "post": {
        "operationId": "createWorkspace",
        "summary": "Launch a new Linux MicroVM Cloud Sandbox",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name"],
                "properties": {
                  "name": {"type": "string"},
                  "vcpu": {"type": "integer", "default": 2},
                  "memory_mb": {"type": "integer", "default": 4096}
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sandbox launched",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {"$ref": "#/components/schemas/Workspace"}
                  }
                }
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "402": {"$ref": "#/components/responses/ApiError"}
        }
      }
    },
    "/workspaces/{id}/commands": {
      "post": {
        "operationId": "runWorkspaceCommand",
        "summary": "Execute bash/python command in MicroVM Cloud Sandbox",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Public Sandbox ID or slug",
            "schema": {"type": "string"}
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["command"],
                "properties": {
                  "command": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Command and argument array (e.g. ['python3', '-c', 'print(1)'])"
                  },
                  "timeout_seconds": {"type": "integer", "default": 60}
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Command execution result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {"type": "string"},
                        "status": {"type": "string"},
                        "exit_code": {"type": "integer"},
                        "output": {
                          "type": "object",
                          "properties": {
                            "stdout": {"type": "string"},
                            "stderr": {"type": "string"}
                          }
                        },
                        "duration_ms": {"type": "integer"}
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/ApiError"},
          "404": {"$ref": "#/components/responses/ApiError"}
        }
      }
    },
    "/api-keys": {
      "get": {
        "operationId": "listApiKeys",
        "summary": "List API keys for the organization",
        "responses": {
          "200": {
            "description": "API keys list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {"$ref": "#/components/schemas/ApiKey"}
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createApiKey",
        "summary": "Generate a new API key",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name"],
                "properties": {
                  "name": {"type": "string"},
                  "service": {"type": "string", "enum": ["full_access", "cloud_sandbox", "ai_gateway"], "default": "full_access"},
                  "expires_in_days": {"type": "integer"},
                  "requests_per_minute": {"type": "integer"},
                  "monthly_spend_limit_microusd": {"type": "integer"}
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API Key created (plaintext returned once)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {"$ref": "#/components/schemas/ApiKeyCreated"}
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "VERBAREX API key (vx_live_...)"
      }
    },
    "responses": {
      "Unauthorized": {"description": "Authentication failed", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "ApiError": {"description": "Request failed", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}}
    },
    "schemas": {
      "Model": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "slug": {"type": "string"},
          "name": {"type": "string"},
          "context_tokens": {"type": "integer"},
          "status": {"type": "string"}
        }
      },
      "Workspace": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "public_id": {"type": "string"},
          "name": {"type": "string"},
          "status": {"type": "string"},
          "session_status": {"type": "string"},
          "created_at": {"type": "string"}
        }
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "public_id": {"type": "string"},
          "name": {"type": "string"},
          "key_prefix": {"type": "string"},
          "service": {"type": "string"},
          "active": {"type": "boolean"},
          "last_used_at": {"type": "string"}
        }
      },
      "ApiKeyCreated": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "name": {"type": "string"},
          "key": {"type": "string"},
          "key_prefix": {"type": "string"},
          "scopes": {"type": "array", "items": {"type": "string"}}
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {"type": "string", "example": "deepseek-v4.1-flash"},
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["role", "content"],
              "properties": {
                "role": {"type": "string", "enum": ["system", "user", "assistant"]},
                "content": {"type": "string"}
              }
            }
          },
          "temperature": {"type": "number", "default": 0.3},
          "max_tokens": {"type": "integer"},
          "stream": {"type": "boolean", "default": false}
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "object": {"type": "string"},
          "created": {"type": "integer"},
          "model": {"type": "string"},
          "choices": {"type": "array", "items": {"type": "object"}},
          "usage": {"type": "object"},
          "verbarex": {"type": "object"}
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": ["error", "request_id"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {"type": "string"},
              "message": {"type": "string"},
              "details": {"type": "object"}
            }
          },
          "request_id": {"type": "string"}
        }
      }
    }
  }
}
