Modal free tier explained
Quick answer
The
Modal platform offers a free tier that includes limited GPU hours and CPU usage for running serverless functions with GPU acceleration. You can start using the free tier by signing up and setting your API key in the environment, then deploying Python functions with GPU support using modal.App and @app.function(gpu=...) decorators.PREREQUISITES
Python 3.8+Modal account with free tier accesspip install modal
Setup
Install the modal Python package and set your Modal API key as an environment variable to access the free tier.
pip install modal output
Collecting modal Downloading modal-1.x.x-py3-none-any.whl (xx kB) Installing collected packages: modal Successfully installed modal-1.x.x
Step by step
Use the free tier by writing a simple Python function with GPU support and deploying it with Modal.
import os
import modal
# Set your Modal API key in environment variable before running
# export MODAL_API_KEY=os.environ["MODAL_API_KEY"]
app = modal.App("my-free-tier-app")
@app.function(gpu="A10G", image=modal.Image.debian_slim().pip_install("torch"))
def run_inference(prompt: str) -> str:
import torch
# Dummy inference example
return f"Processed prompt: {prompt}"
if __name__ == "__main__":
with modal.runner.deploy_stub(app):
result = run_inference.remote("Hello from Modal free tier")
print(result) output
Processed prompt: Hello from Modal free tier
Common variations
You can run CPU-only functions by omitting the gpu parameter or use different GPU types if available in your free tier. Async functions and web endpoints are also supported.
import modal
app = modal.App("my-app")
# CPU-only function
@app.function()
def cpu_task(x: int) -> int:
return x * x
# Async function example
@app.function()
async def async_task(msg: str) -> str:
return f"Async received: {msg}"
# Web endpoint example
@app.function().web_endpoint(method="POST")
def echo(request):
data = request.json()
return {"echo": data.get("message", "")} Troubleshooting
- If you see authentication errors, ensure
MODAL_API_KEYis set correctly in your environment. - If GPU resources are unavailable, check your free tier usage limits or upgrade your plan.
- For deployment issues, verify your function decorators and Modal app name are correct.
Key Takeaways
- Modal free tier provides limited GPU and CPU hours for serverless function deployment.
- Set
MODAL_API_KEYenvironment variable to authenticate your Modal client. - Use
@app.function(gpu="A10G")decorator to run GPU workloads on the free tier. - You can deploy CPU-only, async, and web endpoint functions within the free tier limits.