{
  "openapi": "3.1.0",
  "info": {
    "title": "Physical AI Parts Agent Commerce API",
    "version": "2.0.0",
    "description": "Read approved Physical AI Parts inventory publicly. Privileged agent checkout and order status require a revocable owner-issued credential with explicit scopes and limits."
  },
  "servers": [
    {
      "url": "https://qvrvjmktcdjskvojhqpd.supabase.co/functions/v1/agent-commerce"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "summary": "Search approved marketplace inventory",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "part_number",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Approved inventory catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create authorized agent checkout or check its order status",
        "security": [
          {
            "agentCredential": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": ["action", "listing_id", "buyer_email"],
                    "properties": {
                      "action": {
                        "const": "checkout"
                      },
                      "listing_id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "buyer_email": {
                        "type": "string",
                        "format": "email"
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": ["action", "session_id", "buyer_email"],
                    "properties": {
                      "action": {
                        "const": "status"
                      },
                      "session_id": {
                        "type": "string"
                      },
                      "buyer_email": {
                        "type": "string",
                        "format": "email"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout URL or order status"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Missing, invalid, expired or insufficient agent credential"
          },
          "403": {
            "description": "Owner approval or spending policy denied the action"
          },
          "409": {
            "description": "Listing unavailable/out of stock/seller not ready"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "agentCredential": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pap_live_ owner-issued agent credential",
        "description": "Created and revoked by the human owner at https://physicalaiparts.com/agent-access.html"
      }
    }
  }
}
