Deploying PraisonAI Agents as APIs
Learn how to deploy PraisonAI agents as RESTful APIs for production environments
PraisonAI agents can be easily deployed as RESTful APIs, allowing you to integrate them into various applications and services. This guide covers how to deploy both single and multiple agents as APIs.
Quick Start
Install Dependencies
Make sure you have the required packages installed:
Set API Key
Deploy a Simple Agent API
Create a file named simple-api.py
with the following code:
Run the API Server
Your API will be available at http://localhost:3030/ask
Making API Requests
Once your agent is deployed, you can make POST requests to interact with it:
The response will be in JSON format:
Multi-Agent API Deployment
You can deploy multiple agents on the same server, each with its own endpoint:
With this setup, you can access:
- Weather agent at
http://localhost:3030/weather
- Stock agent at
http://localhost:3030/stock
- Travel agent at
http://localhost:3030/travel
Production Deployment Options
For production environments, consider the following deployment options:
Docker Deployment
Create a Dockerfile
Create requirements.txt
Build and Run Docker Container
Cloud Deployment
Deploying to AWS
Create an EC2 Instance
Launch an EC2 instance with Ubuntu or Amazon Linux.
Install Dependencies
Configure Security Group
Make sure to open port 3030 in your security group settings.
Run with Systemd
Create a systemd service file for automatic startup and management.
Deploying to Google Cloud Run
Build Docker Image
Push to Container Registry
Deploy to Cloud Run
API Configuration Options
When launching your agent as an API, you can customize various parameters:
Securing Your API
For production deployments, consider implementing:
- API Key Authentication: Require API keys for all requests
- Rate Limiting: Limit the number of requests per client
- HTTPS: Use SSL/TLS certificates for encrypted communication
- Input Validation: Validate all input data before processing
Monitoring and Scaling
For production environments, consider:
- Load Balancing: Distribute traffic across multiple instances
- Auto-Scaling: Automatically adjust resources based on demand
- Logging: Implement comprehensive logging for debugging
- Monitoring: Set up alerts for errors and performance issues
Features
RESTful API
Deploy your agents as standard RESTful APIs for easy integration.
Multi-Agent Support
Deploy multiple agents with different endpoints on the same server.
Customizable
Configure ports, paths, CORS settings, and more.
Production-Ready
Easily deploy to Docker, AWS, Google Cloud, or other cloud platforms.
Was this page helpful?