{
  "openapi": "3.1.0",
  "info": {
    "title": "NGT x402 Agent Gateway",
    "version": "2.0.0",
    "description": "Payment-gated agent stream on Base Mainnet, chain 8453. An unpaid GET /v1/agent/stream returns HTTP 402 and a base64 PAYMENT-REQUIRED challenge. Retry with PAYMENT-SIGNATURE set to base64 JSON: {\"x402Version\":2,\"accepted\":<accepts[0]>,\"payload\":{\"signature\":\"0x...\",\"authorization\":{\"from\",\"to\",\"value\",\"validAfter\",\"validBefore\",\"nonce\"}}}. The asset field is accepted.asset. The chain id is accepted.network. The EIP-712 domain name and version are accepted.extra.name and accepted.extra.version. validBefore must fall inside maxTimeoutSeconds. A missing signature, a malformed envelope, an expired authorization, and a facilitator failure all return HTTP 402."
  },
  "servers": [
    {
      "url": "https://ngt-x402-gateway.onrender.com",
      "description": "Public gateway. Settlement is NGT on Base Mainnet."
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Gateway health",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "The gateway process is up.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["ok", "network", "asset"],
                  "properties": {
                    "ok": { "type": "boolean" },
                    "network": { "type": "string", "examples": ["eip155:8453"] },
                    "asset": { "type": "string", "examples": ["0xc97b05F2F68D5CED7aB65F83ab5f4f7A64d9CC44"] }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/agent/stream": {
      "get": {
        "summary": "Open the paid agent stream",
        "operationId": "getAgentStream",
        "description": "Returns HTTP 402 until PAYMENT-SIGNATURE carries a valid EIP-3009 authorization for the NGT price. A successful settlement responds with stream, payer, and transaction.",
        "parameters": [
          {
            "name": "PAYMENT-SIGNATURE",
            "in": "header",
            "required": false,
            "description": "Base64 JSON payment envelope. Omit it to receive the 402 challenge. X-PAYMENT-SIGNATURE is accepted as the same value.",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "The payment settled and the stream is open.",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64 JSON settlement record with success, transaction, network, and payer.",
                "schema": { "type": "string" }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["stream", "payer", "transaction"],
                  "properties": {
                    "stream": { "const": "open" },
                    "payer": {
                      "type": "string",
                      "description": "Address that signed the EIP-3009 authorization.",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    },
                    "transaction": {
                      "type": "string",
                      "description": "Base transaction hash for the NGT transferWithAuthorization settlement."
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment is missing or was rejected. The error field says why. Read PAYMENT-REQUIRED, sign accepts[0], and retry. This status also covers a malformed envelope, a missing nonce, an expired validBefore, a window longer than maxTimeoutSeconds, a wrong asset or amount, and a facilitator failure.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64 JSON challenge. accepts[0] contains scheme, network, amount, asset, payTo, maxTimeoutSeconds, and extra.name, extra.version, extra.nonce.",
                "schema": { "type": "string" }
              },
              "X-PAYMENT-REQUIRED": {
                "description": "Same base64 challenge as PAYMENT-REQUIRED.",
                "schema": { "type": "string" }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["x402Version", "error", "resource", "accepts"],
                  "properties": {
                    "x402Version": { "const": 2 },
                    "error": { "type": "string" },
                    "resource": {
                      "type": "object",
                      "properties": {
                        "url": { "type": "string" },
                        "description": { "type": "string" },
                        "mimeType": { "type": "string" }
                      }
                    },
                    "accepts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": ["scheme", "network", "amount", "asset", "payTo", "maxTimeoutSeconds", "extra"],
                        "properties": {
                          "scheme": { "const": "exact" },
                          "network": { "type": "string", "examples": ["eip155:8453"] },
                          "amount": { "type": "string", "examples": ["1000000000000000"] },
                          "asset": { "type": "string", "examples": ["0xc97b05F2F68D5CED7aB65F83ab5f4f7A64d9CC44"] },
                          "payTo": { "type": "string", "examples": ["0x675199F0b5F76f6b89D7B29c2ADf27C452E06784"] },
                          "maxTimeoutSeconds": { "type": "integer", "examples": [60] },
                          "extra": {
                            "type": "object",
                            "required": ["name", "version", "nonce"],
                            "properties": {
                              "assetTransferMethod": { "const": "eip3009" },
                              "name": { "const": "NextGen Token" },
                              "version": { "const": "1" },
                              "nonce": { "type": "string" }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
