> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

<Steps>
  <Step title="Install PraisonAI">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    pip install praisonai
    ```
  </Step>

  <Step title="Set API Key">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    export OPENAI_API_KEY="your-key"
    ```
  </Step>

  <Step title="Initialize Deploy Config">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    praisonai deploy init --file agents.yaml --type api
    ```
  </Step>

  <Step title="Deploy">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    praisonai deploy run --file agents.yaml --type api
    ```

    **Expected Output:**

    ```
    🚀 Starting deployment...

    ✅ Deployment successful!
    🔗 URL: http://127.0.0.1:8005

    Metadata:
      • type: api
      • host: 127.0.0.1
      • port: 8005
      • workers: 1
    ```
  </Step>

  <Step title="Verify">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    curl http://127.0.0.1:8005/health
    ```
  </Step>
</Steps>

## Quick Start - SDK

<Steps>
  <Step title="Create Deploy Script">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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}")
    ```
  </Step>

  <Step title="Run">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    python deploy_api.py
    ```
  </Step>
</Steps>

## Deploy from YAML

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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: false
```

## API 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:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai deploy run --file agents.yaml --type api --background
```

## Deploy 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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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)

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai deploy status --file agents.yaml
```

**Expected 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

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai deploy destroy --file agents.yaml
```

## Agent.launch() Method

For simple single-agent deployments:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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: /ask
```

## Agents.launch() Method

For multi-agent deployments:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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/docs
```

## launch() 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

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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](./index) - All deploy commands
* [Docker Deploy](./docker) - Deploy to Docker
* [AWS Deploy](./aws) - Deploy to AWS ECS/Fargate
* [GCP Deploy](./gcp) - Deploy to Google Cloud Run
