{
  "openapi": "3.1.0",
  "info": {
    "title": "OSA Procurement Guard API",
    "version": "0.2.0",
    "description": "Pre-purchase trust, pricing and policy decisions for AI agents buying APIs and MCP tools."
  },
  "servers": [
    {
      "url": "https://pkctqxeydfuiupadaoov.supabase.co/functions/v1/procurement-guard"
    }
  ],
  "paths": {
    "/decision": {
      "post": {
        "operationId": "procurementDecision",
        "summary": "Return ALLOW, HOLD or DENY before a machine purchase",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Optional OSA-monitored registry name"
                  },
                  "endpoint": {
                    "type": "string",
                    "format": "uri"
                  },
                  "network": {
                    "type": "string"
                  },
                  "asset": {
                    "type": "string"
                  },
                  "capability": {
                    "type": "string",
                    "description": "Explicit capability used for equivalent-service search"
                  },
                  "offered_price_usd": {
                    "type": "number",
                    "minimum": 0
                  },
                  "max_price_usd": {
                    "type": "number",
                    "minimum": 0
                  },
                  "min_trust": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "name"
                    ]
                  },
                  {
                    "required": [
                      "endpoint"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Policy decision",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "API key required"
          },
          "402": {
            "description": "Invalid API key or no credits"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "Decision": {
        "type": "object",
        "required": [
          "decision",
          "risk_score",
          "reason_codes",
          "methodology_version",
          "credits_remaining"
        ],
        "properties": {
          "decision": {
            "type": "string",
            "enum": [
              "ALLOW",
              "HOLD",
              "DENY"
            ]
          },
          "risk_score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "trust": {
            "anyOf": [
              {
                "type": "object"
              },
              {
                "type": "null"
              }
            ]
          },
          "trust_scope": {
            "type": "string",
            "enum": [
              "linked_endpoint_host",
              "registry_only",
              "name_endpoint_mismatch",
              "unavailable"
            ]
          },
          "market": {
            "anyOf": [
              {
                "type": "object"
              },
              {
                "type": "null"
              }
            ]
          },
          "policy_capability": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "price_history_points": {
            "type": "integer"
          },
          "price_baseline_30d_usd": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "price_drift_pct": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "cheaper_equivalents": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "reason_codes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "methodology_version": {
            "type": "string"
          },
          "credits_remaining": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    }
  }
}