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

> ## Agent Instructions
> Install the Beam CLI, sign in, and connect coding agents to the Beam MCP server with `curl -fsSL https://www.beam.cloud/install | sh`. To also create a VM, run `curl -fsSL https://www.beam.cloud/install | sh -s -- --vm`.
> VMs are persistent Linux machines without GPUs. Defaults: 4 CPUs, 8 GiB of RAM, a 50 GiB disk, Ubuntu 24.04, and a browser desktop. A running VM accrues usage until you stop, pause, or remove it, or until an idle timeout puts it to sleep.
> Stopping a VM keeps its disk and discards RAM and processes. Pausing keeps both, and resuming restores them. To pause after 5 idle minutes and wake on access, run `beam vm update NAME --ttl 300 --idle-action pause --auto-resume`.
> Core VM commands: `beam vm new NAME`, `beam vm ssh NAME`, `beam vm sync NAME ./dir`, `beam vm exec NAME -- CMD`, `beam vm expose NAME PORT --protected`, `beam vm fork NAME NEW_NAME`, `beam vm pause NAME`, `beam vm stop NAME`, `beam vm rm NAME`.
> For GPUs, use a sandbox or a deployed endpoint. Sandboxes are disposable environments that boot in seconds and fork from snapshots.
> Current rates are at https://www.beam.cloud/pricing.

# Creating a Web Endpoint

> Deploying and invoking web endpoints on Beam

Beam allows you to deploy web endpoints that can be invoked via HTTP requests. These endpoints can be used to run arbitrary code. For instance, you could perform inference using one of our GPUs, or just run a simple function that multiplies two numbers.

```python theme={null}
from beam import endpoint

@endpoint(
    cpu=1.0,
    memory=128,
)
def multiply(**inputs):
    result = inputs["x"] * 2
    return {"result": result}
```

> [!TIP]
>
> **Endpoints vs. Task Queues**
>
> Endpoints are RESTful APIs, designed for synchronous tasks that can complete in 180 seconds or less. For longer running tasks, you'll want to use an asynchronous [`task_queue`](https://docs.beam.cloud/v2/task-queue/running-tasks) instead.

#### Launch a Preview Environment (Optional)

[`beam serve`](https://docs.beam.cloud/v2/reference/cli#serve) monitors changes in your local file system, live-reloads the remote environment as you work, and forwards remote container logs to your local shell.

Serve is great for prototyping. You can develop in a containerized cloud environment in real-time, with adjustable CPU, memory, GPU resources.

It's also great for testing an app before deploying it. Served functions are orchestrated identically to deployments, which means you can test your Beam workflow end-to-end before deploying.

To start an ephemeral `serve` session, you'll use the `serve` command:

```sh theme={null}
beam serve [FILE.PY]:[ENTRY-POINT]
```

For example, to start a session for the `multiply` function in `app.py`, run:

```sh theme={null}
beam serve app.py:multiply
```

To end the session, you can use `Ctrl + C` in the terminal where you started the session.

> [!WARNING]
>
> Serve sessions end automatically after 10 minutes of inactivity. The entire
> duration of the session is counted towards billable usage, even if the session
> is not receiving requests.

> [!TIP]
>
> By default, Beam will sync all the files in your working directory to the
> remote container. This allows you to use the files you have locally while
> developing. If you want to prevent some files from getting uploaded, you can
> create a [`.beamignore`](https://docs.beam.cloud/v2/reference/cli#ignore-local-files).

### Deploying the Endpoint

When you're finished with prototyping and want to make a persistent deployment of the endpoint, enter your shell and run this command from the working directory:

```bash theme={null}
beam deploy [FILE.PY]:[ENTRY-POINT]
```

After running this command, you'll see some logs in the console that show the progress of your deployment.

> [accordion] Show Logs
>
> ```bash theme={null}
> $ beam deploy app.py:multiply
>
> => Building image
> => Using cached image
> => Syncing files
> Reading .beamignore file
> => Files synced
> => Deploying endpoint
> => Deployed
> => Invocation details
>
> curl -X POST 'https://multiply-712408b-v1.app.beam.cloud' \
> -H 'Accept: _/_' \
> -H 'Accept-Encoding: gzip, deflate' \
> -H 'Connection: keep-alive' \
> -H 'Authorization: Bearer [YOUR_AUTH_TOKEN]' \
> -H 'Content-Type: application/json' \
> -d '{}'
>
> ```

> [!NOTE]
>
> The container handling the endpoint will spin down after 180 seconds of inactivity by default, or customized with the `keep_warm_seconds` parameter. The container will be billed for the time it is active and handling requests.

### Calling the Endpoint

After deploying the API, you'll be able to make a web request to hit the API with cURL or libraries of your choice.

> [tab] cURL
>
> Open another terminal window to invoke the API:
>
> ### Example Request
>
> ```sh theme={null}
> curl -X POST 'https://multiply-712408b-v1.app.beam.cloud' \
> -H 'Accept: */*' \
> -H 'Accept-Encoding: gzip, deflate' \
> -H 'Connection: keep-alive' \
> -H 'Authorization: Bearer [YOUR_AUTH_TOKEN]' \
> -H 'Content-Type: application/json' \
> -d '{"x": 10}'
> ```
>
> ### Example Response
>
> ```json theme={null}
> {
>   "result": 20
> }
> ```

> [tab] Python
>
> In Python, you can use the `requests` library to make a POST request to the endpoint:
>
> ```python theme={null}
> import requests
>
> url = "https://multiply-712408b-v1.app.beam.cloud"
> headers = {
>   "Connection": "keep-alive",
>   "Content-Type": "application/json",
>   "Authorization": "Bearer [YOUR_AUTH_TOKEN]",
> }
> data = {"x": 10}
>
> response = requests.post(url, headers=headers, json=data)
> print(response.json())
> ```
>
> ### Example Response
>
> ```json theme={null}
> { "result": 20 }
> ```

To send other payloads other than JSON, you can encode the data as a base64 string and include it in the JSON payload, or upload the file to a S3 bucket and mount the bucket to the endpoint.

For more detailed examples, checkout the [Sending File Payloads](https://docs.beam.cloud/v2/endpoint/sending-file-payloads.md) documentation.

```
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.