Deploy: API Server
Deploy agents as a local API server using praisonai deploy
Deploy agents as a local FastAPI server using praisonai deploy run --type api.
Quick Start – CLI
- Install PraisonAI
bash pip install praisonai - Set API Key
bash export OPENAI_API_KEY="your-key" - Initialize Deploy Config
bash praisonai deploy init --file agents.yaml --type api - Deploy
bash praisonai deploy run --file agents.yaml --type apiExpected Output:
🚀 Starting deployment... ✅ Deployment successful! 🔗 URL: http://127.0.0.1:8005 Metadata: • type: api • host: 127.0.0.1 • port: 8005 • workers: 1 - Verify
bash curl http://127.0.0.1:8005/health
Quick Start – SDK
- Create Deploy Script
python from praisonai.deploy import Deploy, DeployConfig, DeployType from praisonai.deploy.models import APIConfig config = DeployConfig( type=DeployType.API, api=APIConfig( host="127.0.0.1", port=8005, workers=1, cors_enabled=True, auth_enabled=False, reload=False ) ) deploy = Deploy(config, "agents.yaml") result = deploy.deploy() print(f"URL: {result.url}") - Run
bash python deploy_api.py
Deploy from YAML
from praisonai.deploy import Deploy
# Load config from agents.yaml deploy section
deploy = Deploy.from_yaml("agents.yaml")
result = deploy.deploy()
print(f"Success: {result.success}")
print(f"URL: {result.url}")agents.yaml with Deploy Config
framework: praisonai
topic: helpful assistant
roles:
assistant:
role: Assistant
goal: Help users with their questions
backstory: You are a helpful assistant
tasks:
help_task:
description: Answer user questions
expected_output: Helpful response
deploy:
type: api
api:
host: "127.0.0.1"
port: 8005
workers: 1
cors_enabled: true
auth_enabled: false
reload: falseAPI Config Options
| Field | Type | Default | Description |
|---|---|---|---|
host | string | 127.0.0.1 | Server host |
port | int | 8005 | Server port |
workers | int | 1 | Number of worker processes |
cors_enabled | bool | true | Enable CORS |
auth_enabled | bool | false | Enable authentication |
auth_token | string | null | Authentication token |
reload | bool | false | Enable auto-reload (dev) |
CLI Flags
| Flag | Type | Default | Description |
|---|---|---|---|
--file, -f | string | agents.yaml | Path to agents.yaml |
--type | choice | – | Must be api |
--background | flag | false | Run in background |
--json | flag | false | Output as JSON |
Background Mode
Run the API server in background:
praisonai deploy run --file agents.yaml --type api --backgroundDeploy Methods (SDK)
| Method | Description |
|---|---|
deploy(background=False) | Execute deployment |
plan() | Generate deployment plan without executing |
status() | Get current deployment status |
doctor() | Run health checks |
destroy(force=False) | Destroy/delete deployment |
Status & Management
from praisonai.deploy import Deploy
deploy = Deploy.from_yaml("agents.yaml")
# Check status
status = deploy.status()
print(f"State: {status.state}")
print(f"URL: {status.url}")
print(f"Healthy: {status.healthy}")
# Run health checks
report = deploy.doctor()
for check in report.checks:
print(f"{check.name}: {'✅' if check.passed else '❌'} {check.message}")
# Destroy deployment
result = deploy.destroy(force=True)
print(f"Destroyed: {result.success}")Check Status (CLI)
praisonai deploy status --file agents.yamlExpected Output:
📊 Checking deployment status...
╭─────────────────────────────────────────────────────────────────────────────╮
│ Deployment Status │
├─────────────────┬───────────────────────────────────────────────────────────┤
│ Property │ Value │
├─────────────────┼───────────────────────────────────────────────────────────┤
│ State │ RUNNING │
│ Service Name │ praisonai-api │
│ Provider │ api │
│ URL │ http://127.0.0.1:8005 │
│ Healthy │ ✅ Yes │
│ Instances │ 1/1 │
╰─────────────────┴───────────────────────────────────────────────────────────╯Stop Server
praisonai deploy destroy --file agents.yamlAgent.launch() Method
For simple single-agent deployments:
from praisonaiagents import Agent
agent = Agent(instructions="You are a helpful assistant.", llm="gpt-4o-mini")
agent.launch(path="/ask", port=8000)Output:
🚀 Agent 'Agent' available at http://0.0.0.0:8000
✅ FastAPI server started at http://0.0.0.0:8000
📚 API documentation available at http://0.0.0.0:8000/docs
🔌 Available endpoints: /askAgents.launch() Method
For multi-agent deployments:
from praisonaiagents import Agent, AgentTeam
researcher = Agent(name="Researcher", instructions="Research topics", llm="gpt-4o-mini")
writer = Agent(name="Writer", instructions="Write content", llm="gpt-4o-mini")
agents = AgentTeam(agents=[researcher, writer])
agents.launch(path="/content", port=8000)Output:
🚀 Multi-Agent HTTP API available at http://0.0.0.0:8000/content
📊 Available agents for this endpoint (2): Researcher, Writer
🔗 Per-agent endpoints: /content/researcher, /content/writer
✅ FastAPI server started at http://0.0.0.0:8000
📚 API documentation available at http://0.0.0.0:8000/docslaunch() Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
path | str | "/" | API endpoint path |
port | int | 8000 | Server port |
host | str | "0.0.0.0" | Server host |
debug | bool | False | Debug mode |
protocol | str | "http" | "http" or "mcp" |
Verify Deployment
# Health check
curl http://localhost:8005/health
# Test endpoint
curl -X POST http://localhost:8005/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello"}'Troubleshooting
| Issue | Fix |
|---|---|
| Port in use | Change port in agents.yaml or lsof -i :8005 |
| No agents.yaml | Run praisonai deploy init --type api |
| Missing API key | export OPENAI_API_KEY="your-key" |
| Server not starting | Run praisonai deploy doctor |
| Missing deps | pip install "praisonaiagents[os]" |
| Import error | pip install praisonai |
Related
- Deploy CLI Overview – All deploy commands
- Docker Deploy – Deploy to Docker
- AWS Deploy – Deploy to AWS ECS/Fargate
- GCP Deploy – Deploy to Google Cloud Run