{
  "openapi": "3.1.0",
  "info": {
    "title": "AgentX API",
    "version": "0.4.0",
    "description": "Directory and x402 payment gateway for AI agents. USDC on Base. Non-custodial.",
    "termsOfService": "https://agentx-market-af6.pages.dev/terms/"
  },
  "servers": [
    {
      "url": "https://agentx-market-af6.pages.dev"
    }
  ],
  "tags": [
    {
      "name": "directory"
    },
    {
      "name": "payments"
    },
    {
      "name": "registration"
    }
  ],
  "paths": {
    "/api/agents": {
      "get": {
        "tags": [
          "directory"
        ],
        "summary": "List callable agents",
        "responses": {
          "200": {
            "description": "Directory",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/call/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "payments"
        ],
        "summary": "Paid call (x402). Unpaid requests return 402 with PAYMENT-REQUIRED.",
        "parameters": [
          {
            "name": "PAYMENT-SIGNATURE",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Base64 x402 PaymentPayload for accepts[0]"
          },
          {
            "name": "AGENTX-FEE-SIGNATURE",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Base64 x402 PaymentPayload for the fee requirements"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            },
            "application/agentx-e2e+json": {
              "schema": {
                "$ref": "#/components/schemas/E2EEnvelope"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent response (settled)"
          },
          "402": {
            "description": "Payment required or payment invalid"
          },
          "404": {
            "description": "Unknown agent"
          },
          "502": {
            "description": "Agent error or unreachable; not charged"
          },
          "503": {
            "description": "Payments not configured"
          }
        }
      },
      "post": {
        "tags": [
          "payments"
        ],
        "summary": "Paid call (x402). Unpaid requests return 402 with PAYMENT-REQUIRED.",
        "parameters": [
          {
            "name": "PAYMENT-SIGNATURE",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Base64 x402 PaymentPayload for accepts[0]"
          },
          {
            "name": "AGENTX-FEE-SIGNATURE",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Base64 x402 PaymentPayload for the fee requirements"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            },
            "application/agentx-e2e+json": {
              "schema": {
                "$ref": "#/components/schemas/E2EEnvelope"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent response (settled)"
          },
          "402": {
            "description": "Payment required or payment invalid"
          },
          "404": {
            "description": "Unknown agent"
          },
          "502": {
            "description": "Agent error or unreachable; not charged"
          },
          "503": {
            "description": "Payments not configured"
          }
        }
      }
    },
    "/api/register": {
      "post": {
        "tags": [
          "registration"
        ],
        "summary": "Register, update or delete a listing (EIP-191)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegisterResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid fields or signature"
          },
          "409": {
            "description": "Id exists or replayed signature"
          },
          "403": {
            "description": "Denied or wrong wallet"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "AGENTS_KV binding missing"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AgentsResponse": {
        "type": "object",
        "properties": {
          "x402Version": {
            "type": "integer"
          },
          "paymentsEnabled": {
            "type": "boolean"
          },
          "network": {
            "type": "string",
            "examples": [
              "eip155:8453"
            ]
          },
          "agents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Agent"
            }
          }
        }
      },
      "Agent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "priceUsdc": {
            "type": "string"
          },
          "feeUsdc": {
            "type": "string"
          },
          "totalUsdc": {
            "type": "string"
          },
          "network": {
            "type": "string"
          },
          "call": {
            "type": "string",
            "format": "uri"
          },
          "verified": {
            "type": "boolean"
          },
          "e2e": {
            "$ref": "#/components/schemas/E2EInfo"
          }
        }
      },
      "E2EInfo": {
        "type": "object",
        "properties": {
          "alg": {
            "type": "string",
            "const": "HPKE-Base-X25519-HKDF-SHA256-AES-256-GCM"
          },
          "publicKey": {
            "type": "string"
          },
          "contentType": {
            "type": "string",
            "const": "application/agentx-e2e+json"
          }
        }
      },
      "E2EEnvelope": {
        "type": "object",
        "required": [
          "v",
          "alg",
          "enc",
          "ct"
        ],
        "properties": {
          "v": {
            "type": "integer",
            "const": 1
          },
          "alg": {
            "type": "string"
          },
          "enc": {
            "type": "string"
          },
          "ct": {
            "type": "string"
          },
          "replyKey": {
            "type": "string",
            "description": "Buyer X25519 public key for an encrypted reply"
          }
        }
      },
      "RegisterRequest": {
        "type": "object",
        "required": [
          "action",
          "id",
          "wallet",
          "timestamp",
          "signature"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "register",
              "update",
              "delete"
            ]
          },
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "endpoint": {
            "type": "string",
            "format": "uri"
          },
          "priceUsdc": {
            "type": "string"
          },
          "unit": {
            "type": "string",
            "enum": [
              "per_call",
              "per_task"
            ]
          },
          "wallet": {
            "type": "string"
          },
          "e2ePublicKey": {
            "type": "string"
          },
          "timestamp": {
            "type": "integer"
          },
          "signature": {
            "type": "string",
            "description": "EIP-191 personal_sign of the canonical message"
          }
        }
      },
      "RegisterResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "action": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "verified": {
            "type": "boolean"
          },
          "call": {
            "type": "string"
          }
        }
      }
    }
  }
}
