A production-grade REST API for deploying and managing AI agents in the cloud. This API provides a scalable and secure way to create, manage, and interact with AI agents.
- π Create and manage multiple AI agents
- π Process completions with rate limiting and error handling
- π Track agent metrics and performance
- π Built-in security features
- π― Horizontal scaling support
- π οΈ Easy deployment with Docker
- π« Graceful shutdown handling
- π Comprehensive logging
- β‘ High-performance FastAPI backend
- Python 3.11+
- Docker (optional)
- OpenAI API key (or other LLM provider key)
- Clone the repository:
git clone https://github.com/The-Swarm-Corporation/AgentAPIProduction.git
cd agent-api
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create a
.env
file:
OPENAI_API_KEY=your_api_key_here
PORT=8080
WORKSPACE_DIR=agent_workspace
- Run the server:
python -m uvicorn api.api:app --host 0.0.0.0 --port 8080 --reload
- Build the Docker image:
docker build -t agent-api .
- Run the container:
docker run -d \
-p 8080:8080 \
-e OPENAI_API_KEY=your_api_key_here \
-e PORT=8080 \
--name agent-api \
agent-api
http://localhost:8080/v1
POST /v1/agent
{
"agent_name": "string",
"model_name": "string",
"description": "string",
"system_prompt": "string",
"temperature": 0.1,
"max_loops": 1
}
GET /v1/agents
POST /v1/agent/completions
{
"prompt": "string",
"agent_id": "uuid",
"max_tokens": null,
"temperature_override": 0.5
}
GET /v1/agent/{agent_id}/metrics
For full API documentation, visit /v1/docs
or /v1/redoc
after starting the server.
The API implements rate limiting with the following defaults:
- 2 requests per second
- 30 requests per minute
- 1000 requests per hour
- 10000 requests per day
For production deployment, consider:
- Using a reverse proxy (e.g., Nginx)
- Implementing SSL/TLS
- Setting up monitoring (e.g., Prometheus + Grafana)
- Using environment-specific configuration
- Implementing proper backup strategies
Example docker-compose.yml
for production:
version: '3.8'
services:
agent-api:
build: .
ports:
- "8080:8080"
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- PORT=8080
volumes:
- agent_data:/app/agent_workspace
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 3s
retries: 3
restart: unless-stopped
volumes:
agent_data:
The API can be deployed to various cloud providers:
eb init -p docker agent-api
eb create production
gcloud builds submit --tag gcr.io/PROJECT_ID/agent-api
gcloud run deploy agent-api --image gcr.io/PROJECT_ID/agent-api
az container create \
--resource-group myResourceGroup \
--name agent-api \
--image your-registry.azurecr.io/agent-api \
--dns-name-label agent-api \
--ports 8080
The API implements comprehensive error handling:
- Rate limit exceeded: 429
- Not found: 404
- Internal server error: 500
Error responses follow this format:
{
"detail": {
"error": "string",
"message": "string"
}
}
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Open an issue on GitHub
- Join our Discord community
- Email [email protected]
- FastAPI for the excellent web framework
- Swarms for the agent implementation
- The open-source community
Made with β€οΈ by swarms.ai