{
  "openapi": "3.1.0",
  "info": {
    "title": "Spatial Compiler REST API",
    "version": "0.1.0",
    "summary": "REST API for compiling raw meshes into production-ready, simulation-ready assets.",
    "description": "Headless GPU compilation for 3D geometry and physics. Turn raw AI-generated meshes into production-ready, simulation-ready assets with one API call, delivered natively via MCP and REST. Authenticate with a Spatial Compiler API key as a bearer token (https://appliedmanifold.com/auth.md).",
    "contact": {
      "name": "Applied Manifold, Inc.",
      "url": "https://appliedmanifold.com/"
    }
  },
  "externalDocs": {
    "url": "https://appliedmanifold.com/docs/",
    "description": "Spatial Compiler docs"
  },
  "servers": [
    {
      "url": "https://api.spatialcompiler.dev/v1",
      "description": "Spatial Compiler API host"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/compile": {
      "post": {
        "operationId": "compile_3d_asset",
        "summary": "Compile a raw mesh into a game-ready asset",
        "description": "Welds non-manifold edges, decimates to an exact triangle budget (meshoptimizer), packs xatlas UV atlases and bakes channel-packed ORM textures in a single VRAM pass. dry_run: true returns a 0-credit estimate.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Raw .glb (or CAD) geometry."
                  },
                  "options": {
                    "type": "string",
                    "description": "JSON options, e.g. {\"target_tris\":15000,\"dry_run\":true}"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Typed telemetry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Telemetry"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key."
          },
          "429": {
            "description": "Per-key hourly velocity limit reached."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Spatial Compiler API key as a bearer token."
      }
    },
    "schemas": {
      "Telemetry": {
        "type": "object",
        "description": "Telemetry fields returned by every compilation.",
        "properties": {
          "status": {
            "type": "string"
          },
          "dry_run": {
            "type": "boolean"
          },
          "tris_in": {
            "type": "integer"
          },
          "target_tris": {
            "type": "integer"
          },
          "tris_out": {
            "type": "integer"
          },
          "draw_calls": {
            "type": "object",
            "properties": {
              "before": {
                "type": "integer"
              },
              "after": {
                "type": "integer"
              }
            }
          },
          "vram_bytes": {
            "type": "integer"
          },
          "elapsed_ms": {
            "type": "number"
          },
          "cache": {
            "type": "string",
            "enum": [
              "HIT",
              "MISS"
            ]
          },
          "credits_est": {
            "type": "number"
          }
        }
      }
    }
  }
}
