API Request Tool
The API Request tool allows your agents to interact with any REST API endpoint. It provides complete control over HTTP methods, headers, request bodies, and response handling.
This tool has Default status, meaning it’s production-ready and available on all subscription plans.
Overview
The API Request tool is one of the most versatile tools in PLai Framework, enabling agents to:Connect to APIs
Integrate with any REST API service or endpoint
Custom Headers
Configure authentication, content types, and custom headers
Flexible Methods
Support for GET, POST, PUT, DELETE, and other HTTP methods
Template System
Dynamic URL and body templating with variable substitution
Configuration Parameters
The API endpoint URL with optional template variables
Example:
Variables: Use
Example:
https://api.example.com/users/{{user_id}}/profile
Variables: Use
{{variable_name}} for dynamic substitutionHTTP method for the request
Common values:
Default:
Common values:
GET, POST, PUT, DELETE, PATCH
Default:
GETHTTP headers as a JSON object
Example:
Default:
Example:
{"Authorization": "Bearer {{api_token}}", "User-Agent": "PLai-Agent/1.0"}
Default:
{}Content type for request body
Options:
Options:
application/json- For JSON payloadsapplication/x-www-form-urlencoded- For form data
Request body as JSON template
Example:
Default:
Note: Only used for POST, PUT, PATCH methods
Example:
{"name": "{{user_name}}", "email": "{{user_email}}"}
Default:
{}
Note: Only used for POST, PUT, PATCH methods
Setup Instructions
1
Navigate to Tools
Go to the Tools section in your project dashboard
2
Create API Request Tool
Click Create Tool and select API Request
3
Configure URL
Enter the API endpoint URL in the URL Template field
4
Set HTTP Method
Specify the HTTP method (GET, POST, etc.) in the Method field
5
Configure Headers
Add required headers including authentication in Headers Template
6
Set Content Type
Choose the appropriate content type for your API
7
Configure Body (if needed)
For POST/PUT requests, configure the Body Template
8
Test Configuration
Use the test button to verify your configuration works
9
Add to Agent
Assign this tool to your agents in agent settings
Usage Examples
Basic GET Request
Authenticated API Call
POST Request with Data
CRM Integration (Salesforce)
Common Use Cases
Customer Relationship Management (CRM)
- Salesforce
- HubSpot
- Create/update leads and contacts
- Retrieve customer information
- Update opportunity status
- Sync customer data
Payment Processing
- Stripe
- PayPal
- Process payments
- Manage customer subscriptions
- Handle refunds
- Retrieve transaction history
Communication Services
- Slack
- Discord
- Send messages to channels
- Create private conversations
- Post file attachments
- Manage workspace users
Template Variables
Variable Substitution
The API Request tool supports dynamic variable substitution in URLs and request bodies:Available Variables
Variables are provided by the agent during execution:- User-provided: Variables from chat context or form inputs
- System variables: Current time, agent name, user ID, etc.
- Previous responses: Data from earlier tool calls in the conversation
- Context variables: Information from the current conversation
Conditional Logic
Use conditional templating for dynamic behavior:Response Handling
Response Processing
The API Request tool automatically processes responses:- Status Code Validation: Checks for successful HTTP status codes
- Content Parsing: Automatically parses JSON, XML, or text responses
- Error Handling: Provides meaningful error messages for failures
- Data Extraction: Makes response data available to the agent
Response Format
Successful responses are returned in this format:Error Handling
Common Error Scenarios
Authentication Errors (401/403)
Authentication Errors (401/403)
Cause: Invalid or expired API keys, insufficient permissionsSolutions:
- Verify API key is correct and active
- Check permission scopes for the API key
- Ensure proper header format for authentication
- Confirm the API endpoint supports your authentication method
Rate Limiting (429)
Rate Limiting (429)
Cause: Exceeded API rate limitsSolutions:
- Implement retry logic with exponential backoff
- Reduce request frequency
- Upgrade API plan if available
- Use caching to reduce redundant requests
Bad Request (400)
Bad Request (400)
Cause: Invalid request format or missing required fieldsSolutions:
- Validate request body against API documentation
- Check required fields are included
- Verify data types match API expectations
- Test with API documentation examples
Network Timeouts
Network Timeouts
Cause: Slow API responses or network issuesSolutions:
- Increase timeout values
- Implement retry logic
- Check API status and performance
- Use alternative endpoints if available
Security Best Practices
Secure Configuration
Security Checklist
- Use HTTPS: Always use secure HTTPS endpoints
- Validate Certificates: Ensure SSL certificate validation
- Rotate Keys: Regular API key rotation
- Minimal Permissions: Use API keys with minimal required permissions
- Monitor Usage: Track API usage for unusual activity
- Rate Limiting: Implement client-side rate limiting
Performance Optimization
Caching Strategies
Optimization Tips
- Batch Requests: Combine multiple operations when possible
- Conditional Requests: Use ETags and If-Modified-Since headers
- Compression: Enable gzip compression for large responses
- Connection Pooling: Reuse connections for better performance
Troubleshooting
Debug Mode
Enable detailed logging to troubleshoot issues:Testing Tools
Use these approaches to test your configuration:- API Testing Tools: Postman, Insomnia, or curl
- Mock Servers: Test with mock API responses
- Staging Environments: Test against non-production APIs
- Request Logs: Review detailed request/response logs