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

# Quickstart

## Run a Function in the Cloud

The simplest way to run code on Beam is to add the `@function` decorator to any Python function. Save this to `app.py`:

```python app.py theme={null}
from beam import function


@function(cpu=1, memory="1Gi")
def square(x: int):
    return {"result": x**2}


if __name__ == "__main__":
    print(square.remote(x=12))
```

Run it like any other Python file:

```sh theme={null}
python app.py
```

Beam syncs your code, launches a container, runs the function, and streams the result back to your shell:

```
=> Building image
=> Using cached image
=> Syncing files
=> Files synced
=> Running function: <app:square>
{'result': 144}
=> Function complete
```

The container spins up in seconds, runs your code, and shuts itself down. No idle costs, no infrastructure to clean up.

## Deploy a Web Endpoint

To turn your code into a live web API, swap `@function` for `@endpoint`. We'll include `numpy` in the image to show how easily you can add Python packages.

* `Image()` defines your container environment. You can add Python packages, system dependencies, or even custom Dockerfiles.
* `@endpoint` turns your function into a real, live web API that runs in the cloud.

```python app.py theme={null}
from beam import endpoint, Image


@endpoint(
    name="quickstart",
    cpu=1,
    memory="1Gi",
    image=Image().add_python_packages(["numpy"]),
)
def predict(**inputs):
    x = inputs.get("x", 256)
    return {"result": x**2}
```

### Deployment

Deploy the endpoint to the cloud:

```sh theme={null}
beam deploy app.py:predict
```

### Call the API

When the deploy finishes, Beam prints your endpoint URL along with a ready-to-run `curl` command. Replace `[TOKEN]` with your token and use the URL from your deploy output:

<CodeGroup>
  ```sh curl theme={null}
  curl -X POST 'https://app.beam.cloud/endpoint/quickstart' \
    -H 'Authorization: Bearer [TOKEN]' \
    -H 'Content-Type: application/json' \
    -d '{"x": 12}'
  ```

  ```typescript TypeScript theme={null}
  import { beamOpts, Deployments } from "@beamcloud/beam-js";

  beamOpts.token = process.env.BEAM_TOKEN!;
  beamOpts.workspaceId = process.env.BEAM_WORKSPACE_ID!;

  const deployment = await Deployments.get({
    name: "quickstart",
    stubType: "endpoint/deployment",
  });

  const response = await deployment.call({ x: 12 });
  console.log(response);
  ```
</CodeGroup>

Either way, you'll get back:

```json theme={null}
{ "result": 144 }
```

The container spins up in seconds, runs your code, and shuts itself down. No idle costs. No infrastructure to clean up.

## What Next?

Here are some other things you can try:

* [Customize your container image](/v2/environment/custom-images)
* [Add a GPU to your app](/v2/environment/gpu)
* [Run a scheduled job](/v2/function/scheduled-job)
* [Parallelize a function across 10 containers](/v2/scaling/parallelizing-functions)
