{
  "openapi": "3.0.1",
  "info": {
    "title": "Predicate API",
    "description": "API for sending Ethereum-like transactions to the Predicate network.",
    "license": {
      "name": "MIT"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.predicate.io"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/v1/task": {
      "post": {
        "description": "Processes a transaction by verifying it against the application's policy using Predicate's operator network. Returns a structured response with validation results and compliance status.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Transaction"
              },
              "examples": {
                "example-request": {
                  "summary": "Basic Transaction Request",
                  "value": {
                    "from": "0x38f6001e8ac11240f903CBa56aFF72A1425ae371",
                    "to": "0xe7f2cd31e61b05b7634fc532c59b78a5dfba8080",
                    "data": "0x",
                    "msg_value": "0",
                    "chain_id": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully processed task",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request: The request format is invalid or missing required fields",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "missing_fields": {
                    "summary": "Missing required fields",
                    "value": {
                      "error": 400,
                      "message": "Missing required field: from"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized: Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_token": {
                    "summary": "Missing or invalid token",
                    "value": {
                      "error": 401,
                      "message": "Missing or invalid token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden: The client does not have permission to access the requested resource",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "insufficient_permissions": {
                    "summary": "Insufficient permissions",
                    "value": {
                      "error": 403,
                      "message": "Insufficient permissions"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found: The requested resource could not be found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "not_found": {
                    "summary": "Resource not found",
                    "value": {
                      "error": 404,
                      "message": "Resource not found"
                    }
                  }
                }
              }
            }
          },
          "408": {
            "description": "Request Timeout: The request took too long to process",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "timeout": {
                    "summary": "Request timeout",
                    "value": {
                      "error": 408,
                      "message": "Request timeout"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests: Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "rate_limit_exceeded": {
                    "summary": "Rate limit exceeded",
                    "value": {
                      "error": 429,
                      "message": "Rate limit exceeded"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "internal_error": {
                    "summary": "Internal server error",
                    "value": {
                      "error": 500,
                      "message": "Internal server error"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "service_unavailable": {
                    "summary": "Service unavailable",
                    "value": {
                      "error": 503,
                      "message": "Service unavailable"
                    }
                  }
                }
              }
            }
          },
          "504": {
            "description": "Gateway Timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "gateway_timeout": {
                    "summary": "Gateway timeout",
                    "value": {
                      "error": 504,
                      "message": "Gateway timeout"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/attestation": {
      "post": {
        "description": "Evaluate a transaction against configured policy and return an attestation (chain-name based, supports EVM and Solana)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/V2AttestationRequest"
              },
              "examples": {
                "interface-only": {
                  "summary": "Interface-only request",
                  "value": {
                    "verification_hash": "x-abc123def456",
                    "from": "0x8ba1f109551bD432803012645Hac136c",
                    "chain": "ethereum"
                  }
                },
                "evm": {
                  "summary": "EVM onchain request",
                  "value": {
                    "to": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
                    "from": "0x8ba1f109551bD432803012645Hac136c",
                    "chain": "base"
                  }
                },
                "svm": {
                  "summary": "Solana onchain request",
                  "value": {
                    "to": "5iejgxCq2vnpiwWpf4qwziVhbX2irmgMEghBrD9tmk5p",
                    "from": "8SfpAAUkA4E1ZTSzXiAR51f1iGuVQU4r7kiNUxh7GpVM",
                    "chain": "solana"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully evaluated and returned attestation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V2AttestationResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "V2AttestationRequest": {
        "type": "object",
        "description": "Transaction details to evaluate for policy compliance and to issue a chain-appropriate attestation.",
        "properties": {
          "from": {
            "type": "string",
            "description": "End user's wallet address initiating the transaction. This field is used for policy enforcement and compliance checks."
          },
          "chain": {
            "type": "string",
            "description": "Target blockchain name. Examples: ethereum, sepolia, base, solana."
          },
          "verification_hash": {
            "type": "string",
            "description": "Your project identifier from the dashboard. Required for interface-only integration. Use this OR 'to', not both."
          },
          "to": {
            "type": "string",
            "description": "Your deployed contract or program address. Required for onchain enforcement. Use this OR 'verification_hash', not both."
          },
          "data": {
            "type": "string",
            "description": "Encoded transaction payload. Required when using PredicateClient for function call validation."
          },
          "msg_value": {
            "type": "string",
            "description": "Native token amount (wei for EVM, lamports for Solana). Required when using PredicateClient."
          },
          "user_ip": {
            "type": "string",
            "description": "End-user IP address for geolocation-based policy evaluation."
          }
        },
        "required": [
          "from",
          "chain"
        ]
      },
      "V2AttestationResponse": {
        "type": "object",
        "description": "Evaluation result and attestation payload to embed onchain.",
        "properties": {
          "policy_id": {
            "type": "string",
            "description": "Identifier of the evaluated policy."
          },
          "policy_name": {
            "type": "string",
            "description": "Human-readable display name of the policy as configured in the dashboard."
          },
          "verification_hash": {
            "type": "string",
            "description": "Unique value used to prove contract ownership by setting it as the onchain policyID during onboarding."
          },
          "is_compliant": {
            "type": "boolean",
            "description": "True if the request satisfied the configured policy."
          },
          "attestation": {
            "type": "object",
            "description": "Chain‑appropriate attestation fields for onchain verification.",
            "properties": {
              "uuid": {
                "type": "string",
                "description": "Attestation identifier (UUID v4)."
              },
              "expiration": {
                "type": "integer",
                "format": "int64",
                "description": "Expiration time as Unix timestamp (seconds)."
              },
              "attester": {
                "type": "string",
                "description": "Attester public key or address."
              },
              "signature": {
                "type": "string",
                "description": "Hex-encoded cryptographic signature over the attestation payload. Always 0x-prefixed."
              }
            }
          },
          "reason": {
            "type": "object",
            "description": "Present on non-compliant responses when the policy provides a reason. Not included for compliant responses.",
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code defined by the policy."
              },
              "message": {
                "type": "string",
                "description": "Human-readable explanation of why the evaluation failed."
              }
            }
          }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string",
            "description": "Address of the sender (must be a valid Ethereum address)",
            "example": "0x1234567890123456789012345678901234567890"
          },
          "to": {
            "type": "string",
            "description": "Destination address (the target smart contract which enforces the policy)",
            "example": "0x1234567890123456789012345678901234567890"
          },
          "data": {
            "type": "string",
            "description": "Hex-encoded calldata relevant for the contract function call e.g., amount to lend, recipient address, etc.",
            "example": "0x"
          },
          "msg_value": {
            "type": "string",
            "description": "Amount of ETH (in wei) to send with the transaction",
            "example": "0"
          },
          "chain_id": {
            "type": "integer",
            "format": "uint64",
            "description": "Optional chain ID for the target blockchain. If not provided, defaults to ethereum mainnet (1)",
            "example": 1
          }
        },
        "required": [
          "from",
          "to",
          "data",
          "msg_value"
        ]
      },
      "TransactionResponse": {
        "type": "object",
        "properties": {
          "is_compliant": {
            "type": "boolean",
            "description": "Indicates whether the transaction meets the policy requirements",
            "example": true
          },
          "signers": {
            "type": "array",
            "description": "The addresses that signed off on the users compliance status",
            "items": {
              "type": "string",
              "example": "0xDAc74b6f9B3609E914c924eB87Adff87A30fcDf6"
            }
          },
          "signature": {
            "type": "array",
            "description": "A ECDSA Signature from the Predicate attestation server",
            "items": {
              "type": "string",
              "example": "0x8e10271f744c41e134d0e4ec92931a93a25c249730c1677d5be723831d68d0c660bb3c3aa409ed06d20a07367b1707908c49ef1209f8c50328cb77d2b4cac3821c"
            }
          },
          "expiry_block": {
            "type": "integer",
            "format": "uint64",
            "description": "Timestamp after which this response is no longer valid (prev block number)"
          },
          "task_id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier for the task",
            "example": "e4732bbe-aa8f-44fb-8c09-c73bdc31eeae"
          }
        }
      },
      "Error": {
        "required": [
          "error",
          "message"
        ],
        "type": "object",
        "properties": {
          "error": {
            "type": "integer",
            "format": "int32"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    }
  }
}
