{
  "openapi": "3.1.0",
  "info": {
    "title": "DNO Glass agent API (Gage)",
    "version": "1.0.0",
    "summary": "Invite DNO Glass to bid and get a preliminary glazing takeoff from Gage, DNO's estimating agent.",
    "description": "DNO Glass is a family-owned commercial glazing subcontractor in Calgary, Alberta, working for general contractors since 2021 (commercial projects only; office (403) 703-1522). This API lets a GC, or an AI agent acting for one, read DNO's capabilities, send a bid invite, and run a preliminary Division 08 takeoff priced into a Class 4 budget range. Takeoffs are not bids. Demo mode: invites are stored but nobody is notified yet. Also available as an MCP server at /mcp.",
    "contact": {
      "name": "DNO Glass (contact details to confirm)",
      "url": "https://dno.everthriveai.com"
    }
  },
  "servers": [
    {
      "url": "https://dno.everthriveai.com"
    }
  ],
  "tags": [
    {
      "name": "Gage"
    },
    {
      "name": "Owner",
      "description": "DNO owner only (OWNER_KEY)"
    }
  ],
  "paths": {
    "/api/v1/capabilities": {
      "get": {
        "operationId": "getCapabilities",
        "tags": [
          "Gage"
        ],
        "summary": "Who DNO Glass is, scope, service area, how to invite them to bid, and what Gage can do",
        "responses": {
          "200": {
            "description": "Capabilities",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/bid-invites": {
      "post": {
        "operationId": "inviteDnoToBid",
        "tags": [
          "Gage"
        ],
        "summary": "Invite DNO Glass to bid on a commercial project",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BidInviteInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invite received",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BidInviteResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Storage not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/rates": {
      "get": {
        "operationId": "getRates",
        "tags": [
          "Gage"
        ],
        "summary": "Division 08 pricing categories (key, label, code, unit) and source. Rate values only with the owner key.",
        "responses": {
          "200": {
            "description": "Rates",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Owner-only on this deployment",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "putRates",
        "tags": [
          "Owner"
        ],
        "security": [
          {
            "ownerKey": []
          }
        ],
        "summary": "Save DNO's rates",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "rates"
                ],
                "properties": {
                  "rates": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "category",
                        "rate"
                      ],
                      "properties": {
                        "category": {
                          "type": "string",
                          "enum": [
                            "cw_stick",
                            "cw_unit",
                            "storefront",
                            "window_wall",
                            "windows",
                            "spandrel",
                            "door_pair",
                            "door_single",
                            "auto_entrance",
                            "glass_entrance",
                            "skylight",
                            "replacement",
                            "other"
                          ]
                        },
                        "rate": {
                          "type": "number",
                          "exclusiveMinimum": 0
                        },
                        "label": {
                          "type": "string"
                        },
                        "source_note": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved"
          },
          "401": {
            "description": "Not the owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "resetRates",
        "tags": [
          "Owner"
        ],
        "security": [
          {
            "ownerKey": []
          }
        ],
        "summary": "Reset to demo rates",
        "responses": {
          "200": {
            "description": "Reset"
          },
          "401": {
            "description": "Not the owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/price": {
      "post": {
        "operationId": "price",
        "tags": [
          "Gage"
        ],
        "summary": "Price quantities at DNO's rates server-side: project totals only, no per-line amounts or unit rates",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "lines"
                ],
                "properties": {
                  "lines": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "required": [
                        "category",
                        "qty"
                      ],
                      "properties": {
                        "category": {
                          "type": "string",
                          "enum": [
                            "cw_stick",
                            "cw_unit",
                            "storefront",
                            "window_wall",
                            "windows",
                            "spandrel",
                            "door_pair",
                            "door_single",
                            "auto_entrance",
                            "glass_entrance",
                            "skylight",
                            "replacement",
                            "other"
                          ]
                        },
                        "qty": {
                          "type": "number",
                          "minimum": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lines echoed as {category, unit, qty} (no per-line amounts) + subtotal, gc (8%), contingency (10%), total, range (-15/+25%), source dno|demo. Public money totals are rounded to 2 significant figures. With the owner key: exact totals, and each line has unit_rate and extended."
          },
          "400": {
            "description": "Bad input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (10/min per IP for public calls)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/rates/extract": {
      "post": {
        "operationId": "extractRates",
        "tags": [
          "Owner"
        ],
        "security": [
          {
            "ownerKey": []
          }
        ],
        "summary": "Propose rates from a rate sheet, past estimate or bid summary (images and/or CSV). Never saves.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "images": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 8,
                    "items": {
                      "oneOf": [
                        {
                          "type": "string",
                          "description": "Base64 data (assumed image/jpeg) or a data: URL"
                        },
                        {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "name": {
                              "type": "string",
                              "maxLength": 200
                            },
                            "media_type": {
                              "type": "string",
                              "enum": [
                                "image/jpeg",
                                "image/png",
                                "image/webp",
                                "image/gif",
                                "application/pdf"
                              ]
                            },
                            "data": {
                              "type": "string",
                              "description": "Base64-encoded file content"
                            }
                          }
                        }
                      ]
                    },
                    "description": "Drawing pages (elevations, window/door schedules, Division 08 spec pages). Images up to ~1568 px on the long edge work best."
                  },
                  "csv": {
                    "type": "string",
                    "maxLength": 200000
                  },
                  "notes": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Proposed rates with confidence and source line"
          },
          "400": {
            "description": "No input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not the owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/calibrate": {
      "post": {
        "operationId": "calibrate",
        "tags": [
          "Owner"
        ],
        "security": [
          {
            "ownerKey": []
          }
        ],
        "summary": "Run Gage on a past bid at DNO's saved rates and compare with DNO's real number",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "images",
                  "their_total_cad"
                ],
                "properties": {
                  "images": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 8,
                    "items": {
                      "oneOf": [
                        {
                          "type": "string",
                          "description": "Base64 data (assumed image/jpeg) or a data: URL"
                        },
                        {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "name": {
                              "type": "string",
                              "maxLength": 200
                            },
                            "media_type": {
                              "type": "string",
                              "enum": [
                                "image/jpeg",
                                "image/png",
                                "image/webp",
                                "image/gif",
                                "application/pdf"
                              ]
                            },
                            "data": {
                              "type": "string",
                              "description": "Base64-encoded file content"
                            }
                          }
                        }
                      ]
                    },
                    "description": "Drawing pages (elevations, window/door schedules, Division 08 spec pages). Images up to ~1568 px on the long edge work best."
                  },
                  "project_name": {
                    "type": "string"
                  },
                  "their_total_cad": {
                    "type": "number"
                  },
                  "estimator_hours": {
                    "type": "number"
                  },
                  "scope": {
                    "type": "object",
                    "properties": {
                      "glazing_only": {
                        "type": "boolean",
                        "default": true
                      },
                      "includes_general_conditions": {
                        "type": "boolean",
                        "default": true
                      },
                      "description": {
                        "type": "string"
                      }
                    }
                  },
                  "their_breakdown": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "category": {
                          "type": "string",
                          "enum": [
                            "cw_stick",
                            "cw_unit",
                            "storefront",
                            "window_wall",
                            "windows",
                            "spandrel",
                            "door_pair",
                            "door_single",
                            "auto_entrance",
                            "glass_entrance",
                            "skylight",
                            "replacement",
                            "other"
                          ]
                        },
                        "amount_cad": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Comparison"
          },
          "401": {
            "description": "Not the owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed or no glazing found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/takeoff": {
      "post": {
        "operationId": "runTakeoff",
        "tags": [
          "Gage"
        ],
        "summary": "Preliminary glazing takeoff from drawing pages, priced into a Class 4 budget range",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TakeoffInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Priced takeoff",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TakeoffResult"
                }
              }
            }
          },
          "400": {
            "description": "Bad input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "AI service error or unreadable pages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "AI not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BidInviteInput": {
        "type": "object",
        "required": [
          "project_name",
          "gc_company",
          "contact",
          "site_location",
          "scope",
          "bid_close_date"
        ],
        "properties": {
          "project_name": {
            "type": "string",
            "maxLength": 200
          },
          "gc_company": {
            "type": "string",
            "maxLength": 200,
            "description": "General contractor inviting DNO to bid"
          },
          "contact": {
            "type": "object",
            "required": [
              "name"
            ],
            "description": "Estimator or PM at the GC. Give an email or a phone (or both).",
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 120
              },
              "email": {
                "type": "string",
                "format": "email",
                "maxLength": 200
              },
              "phone": {
                "type": "string",
                "maxLength": 40
              },
              "role": {
                "type": "string",
                "maxLength": 120
              }
            }
          },
          "site_location": {
            "type": "string",
            "maxLength": 300,
            "description": "Street address or city of the job site"
          },
          "project_type": {
            "type": "string",
            "maxLength": 120,
            "description": "e.g. office, retail, institutional. Commercial only."
          },
          "scope": {
            "description": "Glazing scope being tendered, e.g. curtain wall, storefront, entrances (Division 08 sections welcome)",
            "oneOf": [
              {
                "type": "string",
                "maxLength": 2000
              },
              {
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 200
                }
              }
            ]
          },
          "bid_close_date": {
            "type": "string",
            "format": "date",
            "description": "YYYY-MM-DD"
          },
          "glazing_start": {
            "type": "string",
            "maxLength": 40,
            "description": "Expected glazing start (date, month or quarter)"
          },
          "drawings_links": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "https links to the bid set"
          },
          "files": {
            "type": "array",
            "maxItems": 4,
            "items": {
              "oneOf": [
                {
                  "type": "string",
                  "description": "Base64 data (assumed image/jpeg) or a data: URL"
                },
                {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "name": {
                      "type": "string",
                      "maxLength": 200
                    },
                    "media_type": {
                      "type": "string",
                      "enum": [
                        "image/jpeg",
                        "image/png",
                        "image/webp",
                        "image/gif",
                        "application/pdf"
                      ]
                    },
                    "data": {
                      "type": "string",
                      "description": "Base64-encoded file content"
                    }
                  }
                }
              ]
            },
            "description": "Optional uploaded pages, max 4 files of 1500000 bytes each (decoded)"
          },
          "notes": {
            "type": "string",
            "maxLength": 4000
          },
          "agent_name": {
            "type": "string",
            "maxLength": 120,
            "description": "Name of the AI agent sending this on the GC's behalf, if any"
          }
        }
      },
      "BidInviteResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "BR-20261115-K7Q2M"
          },
          "status": {
            "type": "string",
            "enum": [
              "received"
            ]
          },
          "demo": {
            "type": "boolean",
            "description": "true = stored only, nobody at DNO notified"
          },
          "received_at": {
            "type": "string",
            "format": "date-time"
          },
          "project_name": {
            "type": "string"
          },
          "bid_close_date": {
            "type": "string",
            "format": "date"
          },
          "drawings_links": {
            "type": "integer"
          },
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "media_type": {
                  "type": "string"
                },
                "bytes": {
                  "type": "integer"
                },
                "sha256": {
                  "type": "string"
                }
              }
            }
          },
          "message": {
            "type": "string"
          },
          "next_steps": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "TakeoffInput": {
        "type": "object",
        "description": "Send `images` (up to 8 pages) or `sheets` (up to 8 large sheets as tiles). For bigger sets use the takeoff job API.",
        "properties": {
          "sheets": {
            "type": "array",
            "maxItems": 8,
            "description": "Large drawings: each sheet as up to 9 overlapping tiles (<=1568 px each), labelled r<row>c<col>.",
            "items": {
              "type": "object",
              "required": [
                "tiles"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "sheet_number": {
                  "type": "string"
                },
                "sheet_title": {
                  "type": "string"
                },
                "tiles": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 9,
                  "items": {
                    "type": "object",
                    "required": [
                      "data"
                    ],
                    "properties": {
                      "tile": {
                        "type": "string",
                        "description": "r1c1, r1c2, ..."
                      },
                      "media_type": {
                        "type": "string"
                      },
                      "data": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "images": {
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "items": {
              "oneOf": [
                {
                  "type": "string",
                  "description": "Base64 data (assumed image/jpeg) or a data: URL"
                },
                {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "name": {
                      "type": "string",
                      "maxLength": 200
                    },
                    "media_type": {
                      "type": "string",
                      "enum": [
                        "image/jpeg",
                        "image/png",
                        "image/webp",
                        "image/gif",
                        "application/pdf"
                      ]
                    },
                    "data": {
                      "type": "string",
                      "description": "Base64-encoded file content"
                    }
                  }
                }
              ]
            },
            "description": "Drawing pages (elevations, window/door schedules, Division 08 spec pages). Images up to ~1568 px on the long edge work best."
          },
          "context": {
            "type": "object",
            "description": "Optional project context (name, location, type, storeys, notes)",
            "additionalProperties": true
          },
          "gc_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 30,
            "default": 8,
            "description": "General conditions, hoisting & mobilization %"
          },
          "contingency_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 30,
            "default": 10,
            "description": "Design & estimating contingency %"
          }
        }
      },
      "TakeoffResult": {
        "type": "object",
        "properties": {
          "agent": {
            "type": "string"
          },
          "basis": {
            "type": "string"
          },
          "truncated": {
            "type": "boolean"
          },
          "project": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "location": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "storeys": {
                "type": "string"
              }
            }
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "line": {
                  "type": "integer"
                },
                "category": {
                  "type": "string",
                  "enum": [
                    "cw_stick",
                    "cw_unit",
                    "storefront",
                    "window_wall",
                    "windows",
                    "spandrel",
                    "door_pair",
                    "door_single",
                    "auto_entrance",
                    "glass_entrance",
                    "skylight",
                    "replacement",
                    "other"
                  ]
                },
                "section": {
                  "type": "string",
                  "description": "Division 08 section"
                },
                "system": {
                  "type": "string"
                },
                "where": {
                  "type": "string"
                },
                "qty": {
                  "type": "integer"
                },
                "unit": {
                  "type": "string",
                  "enum": [
                    "SF",
                    "EA",
                    "PR"
                  ]
                },
                "extended_cad": {
                  "type": "number",
                  "description": "Owner (OWNER_KEY) calls only. Public responses omit per-line amounts and unit rates (line_amounts: \"private\")."
                },
                "confidence": {
                  "type": "string",
                  "enum": [
                    "high",
                    "medium",
                    "low"
                  ]
                }
              }
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "totals": {
            "type": "object",
            "properties": {
              "currency": {
                "type": "string"
              },
              "glazed_area_sf": {
                "type": "number"
              },
              "openings": {
                "type": "number"
              },
              "subtotal": {
                "type": "number"
              },
              "general_conditions_pct": {
                "type": "number"
              },
              "general_conditions": {
                "type": "number"
              },
              "contingency_pct": {
                "type": "number"
              },
              "contingency": {
                "type": "number"
              },
              "total": {
                "type": "number"
              },
              "range_low": {
                "type": "number",
                "description": "total -15%"
              },
              "range_high": {
                "type": "number",
                "description": "total +25%"
              },
              "excludes": {
                "type": "string"
              }
            }
          },
          "estimate_class": {
            "type": "string"
          },
          "rates": {
            "type": "string"
          },
          "disclaimer": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "fields": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "field": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "ownerKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "DNO owner key (OWNER_KEY). Owner endpoints only."
      }
    }
  }
}