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

# Cloud Deployment

> Deploy your agent to a global serverless network.

Deploying your agent to production takes just one command. Cycls handles the infrastructure, scaling, and security for you.

## Getting Started

Before deploying your agent, you'll need a Cycls API key.

1. Go to the [Cycls Console](https://cycls.com/auth/sign-in) and sign in or create an account.
2. Navigate to the API Keys section.
3. Create a new API key and copy it securely.

## Deploying to Production

To deploy your agent, set your API key and call `app.deploy()`:

```python theme={null}
import cycls
import os

cycls.api_key = os.getenv("CYCLS_API_KEY")

@cycls.app(pip=["openai"], copy=[".env"])
async def app(context):
    from openai import AsyncOpenAI

    client = AsyncOpenAI()
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=context.messages,
        stream=True
    )
    async for chunk in response:
        content = chunk.choices[0].delta.content
        if content:
            yield content

app.deploy()
```

## Environment Variables & Secrets

Create a `.env` file in your project root and include it with `copy=[".env"]`:

```env theme={null}
CYCLS_API_KEY=cy-...
OPENAI_API_KEY=sk-...
```

Cycls automatically loads the `.env` file—environment variables are available via `os.getenv()` inside your function without needing any additional packages.

```python theme={null}
import cycls
import os

cycls.api_key = os.getenv("CYCLS_API_KEY")

@cycls.app(pip=["openai"], copy=[".env"])
async def app(context):
    from openai import AsyncOpenAI

    # Environment variables from .env are automatically loaded
    client = AsyncOpenAI(api_key=os.getenv("OPENAI_API_KEY"))
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=context.messages,
        stream=True
    )
    async for chunk in response:
        content = chunk.choices[0].delta.content
        if content:
            yield content

app.deploy()
```

## What Happens During Deployment?

When you run `app.deploy()`, Cycls performs the following steps:

1. **Build**: Creates a Docker image containing your code, dependencies (`pip`), and system packages (`apt`).
2. **Push**: Uploads the image to the private Cycls Container Registry.
3. **Provision**: Sets up the serverless infrastructure to host your agent.
4. **Deploy**: Launches your agent and assigns it a permanent URL (e.g., `https://app.cycls.ai`).

## Deployment Output

```bash theme={null}
🚀 Deploying...
✅ Deployment successful!
🔗 Service is available at: https://app.cycls.ai
```

## Updating Your Agent

To update your agent, simply make changes to your code and run the script again. Cycls will build a new version and seamlessly update the deployment with zero downtime.

## Local vs Cloud

| Feature    | `app.local()`           | `app.deploy()`            |
| ---------- | ----------------------- | ------------------------- |
| URL        | `http://localhost:8080` | `https://<name>.cycls.ai` |
| Hot Reload | Yes (default)           | No                        |
| SSL        | No                      | Yes (automatic)           |
| Scaling    | Single container        | Auto-scaling              |
| Auth       | Optional                | Optional                  |

## Monitoring & Management

The [Cycls Dashboard](https://cycls.com/dashboard) lets you monitor your agent's performance, view real-time logs, and manage your deployments.
