payment-signature HTTP header (per the x402 protocol).
Nevermined Proxy instances are standard HTTP Proxies in charge of authorizing users trying to access AI Agents or Services.
Get the AI Agent or Service Access Token
The access token is minted against a delegation — a one-time authorization that lets the facilitator spend on the subscriber’s behalf, up to a limit. Create the delegation once withcreateDelegation / create_delegation, then reference it by delegationId whenever you mint a token.
- TypeScript
- Python
Is this a fiat plan or a crypto plan? It determines the
provider/currency above and whether you must pass a scheme. The direct getX402AccessToken call defaults to crypto (nvm:erc4337) — for card plans pass scheme: 'nvm:card-delegation'. See Order Plans for how to detect a plan’s type before you pay.Sending a query to the AI Agent
Once you have a valid X402 access token, you can query the AI Agent by making a standard HTTP request with the token in thepayment-signature header.
This request must be sent directly to the Agent endpoint (the Agent API description is in the Agent Metadata).
Because Nevermined authorizes standard HTTP requests, they can be used to protect any kind of AI Agent or Service exposing an HTTP API.
Using cURL
Using Programming Languages
- TypeScript
- Python
Complete Query Flow Example
Here’s a complete example showing the full flow from getting access tokens to querying an agent:- TypeScript
- Python
Handling Different Response Types
AI agents can return various types of responses. Here’s how to handle them:- TypeScript
- Python
Error Handling and Status Codes
200 - Success
200 - Success
Request was successful and credits were deducted from the user’s balance
402 - Payment Required
402 - Payment Required
User doesn’t have sufficient credits or their plan has expired
403 - Forbidden
403 - Forbidden
User has access but the specific endpoint is not allowed for their plan
429 - Rate Limited
429 - Rate Limited
Too many requests. User should wait before trying again
500 - Server Error
500 - Server Error
Agent internal error. This doesn’t consume credits
Best Practices
Token Management
- Cache access tokens (they’re valid for a limited time)
- Refresh tokens when they expire
- Never expose tokens in client-side logs
Error Handling
- Always check response status codes
- Implement retry logic for network failures
- Handle 402 responses by prompting for plan renewal
Performance
- Reuse access tokens across multiple requests
- Implement request timeouts
- Use appropriate HTTP methods (GET, POST)
Monitoring
- Track credit usage patterns
- Monitor response times and error rates
- Set up alerts for low credit balances
Advanced Usage Patterns
Batch Requests
For efficiency, you can send multiple queries in a single request:- TypeScript
- Python
Streaming Responses
For long-running AI operations, you might want to handle streaming responses:Next Steps
Now that you know how to query AI agents, learn how to:Build AI Agents
Learn how to create AI agents that accept paid requests
Handle Requests
Learn how to process requests and manage responses