Deploy a Simple Web Endpoint

To run your code in the cloud, you just add a decorator. That’s it.

Let’s write a simple function that finds the square of 256.

We include numpy in the container image to show how you can easily add Python packages to your containers.

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

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}

Save this code to a file on your computer. You can name the file whatever you want, but we’ll call it app.py for this example.

Deployment

With the app.py file saved on your computer, you can deploy this to the cloud using this command:

beam deploy app.py:predict

Call the API

After running beam deploy, a cURL command will print in your shell. You can use this command to invoke the API.

Make sure to replace [TOKEN] with your actual token.

curl -X POST 'https://app.beam.cloud/endpoint/quickstart' \
  -H 'Authorization: Bearer [TOKEN]' \
  -H 'Content-Type: application/json' \
  -d '{"x": 12}'

The container spins up in seconds, runs your code, and shuts itself down.

No idle costs. No infrastructure to cleanup.

What Next?

Here are some other things you can try: