Skip to main content
Once a Payment Plan is purchased, User(s) can query all the AI Agents linked to that plan. To ensure AI agents only authorize valid requests (users with credits), we provide a simple API (via the Payments Libraries) that makes validation simple and secure.

Users: Sending Requests to AI Agents

When a user wants to query an AI Agent, they need to send a request with the access token received when purchasing the Payment Plan. This token is used to validate that the user has access to the AI Agent and that they have enough credits.
The access token is minted against a delegation — create it once with createDelegation / create_delegation, then reuse its delegationId. The direct call defaults to crypto (nvm:erc4337); for fiat (card) plans pass scheme: 'nvm:card-delegation'. See Query Agents for the full buyer flow and Order Plans for detecting a plan’s payment type.

AI Agents: Authorizing Only Valid Requests from Users

All the authorization can be done by calling the requests.startProcessingRequest method. This method will receive the access token sent by the user and will validate:
  1. The user is a subscriber of any payment plans linked to the AI agent.
  2. The requested endpoint and that the HTTP method is permitted (as included as part of the AI agent registration).
  3. The user has sufficient credits to pay for the request (in the case of a credits-based Payment Plan) or the payment plan hasn’t expired (in the case of a time-based subscription).
In the example below, we will start a simple HTTP server that will first validate the request using the startProcessingRequest method. If the request is valid, it will return a 200 OK response; otherwise, it will return a 402 Payment Required response.
As you can see, the Payments libraries are framework-agnostic, so you can integrate them with any web framework in TypeScript/JavaScript (Express, Next.js, etc.) or Python (FastAPI, Flask, etc.).

Best Practices for Request Processing

Validation First

Always validate payments before processing expensive AI operations to avoid wasting resources.

Error Handling

Provide clear error messages and appropriate HTTP status codes for different failure scenarios.

Resource Management

Implement timeouts and resource limits to prevent abuse and ensure fair usage.

Monitoring

Log all requests, validation results, and processing times for analytics and debugging.