Endpoint
Request Body
The natural language query to process. Can be omitted if
imageData is provided.Example: "What is the current price of Bitcoin?"USDC payment transaction hash for query verification. The transaction must be confirmed on-chain.Example:
"0x1234567890abcdef..."Wallet address of the user making the payment.Example:
"0xabcdef1234567890..."Base64-encoded image data for image-based queries. Allows image-only queries when
query is omitted.Array of previous messages for context-aware responses.
Session identifier for tracking conversation state and spending across multiple queries.
Maximum budget in USD for x402 agent calls during this query. Prevents runaway costs.Defaults to
X402_DEFAULT_BUDGET_USD environment variable (1 USD).Response Fields
Indicates whether the query was processed successfully.
AI-generated response to the user’s query.
List of agent IDs that were called to generate the response.Example:
["oracle", "scout", "news"]Query cost in USDC (always “0.03” for direct user queries).
The verified payment transaction hash.
Unique identifier for this query’s execution trace.
Total USD spent on x402 agent calls during query processing.
Detailed execution trace with budget tracking and agent call logs.
Examples
Response Example
Error Responses
Missing Required Fields
Payment Verification Failed
Payment Transaction Failed
AI Generation Failed (Payment Confirmed)
Rate Limit Exceeded
Payment Flow
User Sends USDC Payment
User initiates a USDC transfer transaction worth $0.03 to the marketplace contract.
Submit Query with Transaction Hash
Frontend submits the query along with
txHash and userAddress to the /query endpoint.Backend Verifies Payment
Backend calls
publicClient.waitForTransactionReceipt() to verify:- Transaction is mined
- Transaction status is ‘success’
- Transaction matches the provided hash
AI Processing
Once verified, the query is processed using Gemini and x402 agents with budget tracking.
Legacy Flow (Backward Compatibility)
IftxHash is not provided, the backend falls back to the legacy escrow-based flow:
Budget Management
ThebudgetUsd parameter controls spending on x402 agent calls during query processing:
- Default: 1 USD (configurable via
X402_DEFAULT_BUDGET_USDenvironment variable) - Purpose: Prevents runaway costs if AI makes excessive agent calls
- Behavior: Query execution stops when budget is exhausted
- Tracking: Real-time budget tracking in the trace object
Related Endpoints
- GET /providers - Discover available agents
- GET /dashboard/stats - View query statistics
- GET /dashboard/spend - Track session spending