Skip to main content
PraisonAI Agents can be deployed as HTTP APIs or MCP (Model Context Protocol) servers, enabling seamless integration with web applications, microservices, and other systems.
The user deploys an agent as an HTTP or MCP service; external apps call the API instead of importing the SDK directly.

How It Works

An external client calls the launched endpoint, and the agent runs the request before returning the response.

Choose a Protocol

Pick the launch protocol that matches the caller.

Authentication

.launch() binds to 127.0.0.1 by default and enforces a bearer token the moment you expose it beyond localhost. .launch() has three authentication states: Loopback hosts are 127.0.0.1, ::1, and localhost. Anything else (0.0.0.0, a LAN IP) is treated as non-loopback.
Loopback is the default, so no token is needed:
Clients that cannot set Authorization may send X-Auth-Token: <token> instead. Both headers are accepted and compared in constant time.
Migration from before this change: if you ran agent.launch(port=8000) expecting 0.0.0.0, connections from other hosts stop working after upgrade. Pass host="0.0.0.0" explicitly and set PRAISONAI_LAUNCH_AUTH_TOKEN (or use the printed one-time token). This mirrors the earlier praisonai deploy change in API Server Authentication.

Quick Start

1

Install Package

Install PraisonAI Agents:
For MCP support, also install:
2

Create an Agent

Create an agent to deploy as an API:
3

Launch as API

Deploy the agent as an HTTP API:
4

Test the API

Test your deployed agent API:

Launch Methods

HTTP API Server

The most common deployment method is as an HTTP API server using FastAPI:

MCP Server

For Model Context Protocol integration:

API Usage

When launched as an HTTP API, agents expose a single endpoint that accepts POST requests:

HTTP API Endpoint

POST /path Send messages to the agent and receive responses.
The endpoint also supports form data:

Complete Examples

Example 1: Single Agent HTTP API

Example 2: Multi-Agent HTTP API System

Example 3: MCP Server with Tools

Example 4: Multiple Endpoints on Same Port

Multiple Agent / Agents instances may call .launch(port=N) concurrently from different threads — registration is atomic. If two launch calls use the same path on the same port, the second gets an auto-suffixed path (/path_abc123) and a warning is logged. Server readiness is signalled deterministically (no fixed sleep); .launch() returns only after the port is accepting connections. The wait defaults to 5 seconds and is configurable via the PRAISONAI_SERVER_READY_TIMEOUT environment variable. If the server doesn’t become ready in time, .launch() still returns and a warning is logged — check server logs for startup errors.

Example 5: Debug Mode for Development

Launch Parameters

Environment Variables

Client Integration

Python Client

JavaScript Client

MCP Client Integration

For MCP servers, use an MCP-compatible client:

Deployment Best Practices

Performance

  • Use appropriate worker processes
  • Enable connection pooling
  • Monitor resource usage
  • Consider horizontal scaling for high load

Security

  • Set PRAISONAI_LAUNCH_AUTH_TOKEN before exposing beyond localhost; the SDK auto-generates one if you don’t, but a rotation-managed preset token is preferred
  • Deploy behind a reverse proxy (nginx, Apache) for HTTPS and rate limiting
  • Use HTTPS in production
  • Validate and sanitize inputs

Production Deployment

Docker Deployment

Systemd Service

Nginx Reverse Proxy

Important Notes

  1. Threading: The launch() method uses threading to run servers in the background
  2. Blocking: The last launch() call in your script will block the main thread
  3. Multiple Agents: You can run multiple agents on the same port with different paths (HTTP mode only)
  4. Dependencies: HTTP mode requires FastAPI and uvicorn, MCP mode requires praison-mcp
  5. API Documentation: HTTP APIs automatically get FastAPI documentation at /docs

Troubleshooting

  • Check if another process is using the port: lsof -i :8000
  • Kill the process or use a different port
  • Ensure previous agent instances are properly stopped
  • For HTTP: pip install fastapi uvicorn
  • For MCP: pip install praison-mcp mcp
  • Check error messages for specific missing packages
  • Check console for error messages
  • Verify API key is set correctly
  • Test with debug=True for more detailed logs
  • Ensure agent initialization is successful
  • Verify the host and port settings
  • Check firewall rules
  • Ensure the agent is actually running
  • Try connecting from localhost first
If you see Agent server on port N did not become ready within 5.0s in the logs, the FastAPI server took longer than the default 5s to come up. This is usually safe (.launch() still returns and the server keeps starting), but you can raise the wait:
Common causes: slow imports, cold-start on resource-constrained machines, blocking startup hooks.

Next Steps

API Reference

Detailed Agent API documentation

MCP Integration

Learn more about Model Context Protocol

Best Practices

Use protocol="http" for web apps, cURL, and microservices that speak REST, and protocol="mcp" when the caller is an MCP-compatible agent host. HTTP is the default, so agent.launch(port=8000) gives you a POST endpoint with automatic FastAPI docs at /docs. Switch only when the consumer requires MCP tools.
Multiple agents can run on the same port when each uses a unique path. Registration is atomic across threads, but if two .launch() calls reuse the same path on the same port the second is auto-suffixed (/path_abc123) and a warning is logged. Assign explicit, distinct paths (/sales, /support) so clients always hit the agent they expect.
.launch() returns only after the port accepts connections, waiting up to 5 seconds by default. On resource-constrained machines or with heavy imports, raise the wait so startup logs aren’t misread as failures:
A timeout logs a warning but does not abort — the server keeps starting in the background.
The launch server now enforces its own bearer auth: set PRAISONAI_LAUNCH_AUTH_TOKEN before binding to a non-loopback host, or the SDK auto-generates a one-time token and prints it. A reverse proxy (nginx) is still recommended for HTTPS and rate limiting, but it is no longer the only thing standing between the internet and your agent. Bind to 127.0.0.1 (the default) when the proxy runs on the same host.
Run a persistent multi-agent server with richer routing and lifecycle control.
Connect agents to Model Context Protocol tools and servers.