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.AI Agents: Authorizing Only Valid Requests from Users
All the authorization can be done by calling therequests.startProcessingRequest
method. This method will receive the access token sent by the user and will validate:
- The user is a subscriber of any payment plans linked to the AI agent.
- The requested endpoint and that the HTTP method is permitted (as included as part of the AI agent registration).
- 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).
startProcessingRequest
method. If the request is valid, it will return a 200 OK response; otherwise, it will return a 402 Payment Required response.
Integration with Popular Frameworks
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.