Integration Methods
Nevermined offers two main approaches for integrating with AI agents:No-Code Integration (Proxy-Based)
For quick setup with no backend changes, use Nevermined Proxy instances:Nevermined Proxy instances are standard HTTP Proxies that automatically handle user authorization and payment validation for your AI Agents or Services.
- Zero code changes to your existing AI agent
- Automatic payment validation before requests reach your service
- Built-in rate limiting and usage tracking
- Standard HTTP proxy - works with any HTTP-based service
Low-Code Integration (Direct)
For maximum control and customization, integrate directly with your agent code:- Custom payment validation logic in your application
- Fine-grained control over request processing
- Custom error handling and user experience
- Direct integration with the Payments library
Get the AI Agent or Service Access Token
- TypeScript
- Python
Sending a query to the AI Agent
If the response of thegetAgentAccessToken method contains a valid accessToken, the user can query the AI Agent making a standard HTTP request.
This request must be sent directly to the Agent (the description of the Agent API is in the Agent Metadata) or if the agentAccessParams includes an entry in the proxies array, through one of the Nevermined Proxy instances listed in the proxies array of the response.
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
Monitor Usage
Track and optimize your AI service usage