Sitemap

How to Deploy a FastAPI App to FastAPI Cloud with the CLI

3 min read5 hours ago

--

Press enter or click to view image in full size

FastAPI Cloud is now generally available. If your FastAPI app already runs locally, you can start the deployment with one command.
More details: FastAPI Cloud

Let’s create a small FastAPI app and deploy it to FastAPI Cloud via CLI. So, we need a /health endpoint that we can call locally and again after deployment.

1. Create a FastAPI app

I will call the project fastapi-cloud-demo. If you’re starting from scratch,
install uv and run the commands below. uv installation guide

uv init fastapi-cloud-demo --bare
cd fastapi-cloud-demo
uv add "fastapi[standard]"

The —bare flag creates a minimal pyproject.toml.
The fastapi[standard] install includes the CLI we’ll use to deploy.
More details: FastAPI installation guide

Create main.py in the project directory and add this health endpoint:

from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
def health():
return {"status": "ok"}

This app is enough to follow the login and deployment steps.

2. Run the app locally

Check the app before deploying, run:

uv run fastapi dev main.py

Open http://127.0.0.1:8000/health in your browser. You should see {"status":"ok"}.

3. Deploy with the FastAPI CLI

From the project directory, run:

uv run fastapi login
Press enter or click to view image in full size
FastAPI Cloud CLI Authorize Screen
FastAPI CLI authorization screen

The CLI opens the browser. Sign in to FastAPI Cloud and review the CLI authorization request. If you identify it, click Authorize and return to your terminal.

It stores credentials locally, so you don't need to copy a token into your project.

When you return to your terminal, you will see:

  FastAPI Cloud

🔐 Login to FastAPI Cloud

Opening
https://dashboard.fastapicloud.com/device?code=******************

Now you are logged in! 🚀

Now it's time to deploy (if it's Friday, no deploy, please)!

uv run fastapi deploy

Select the team you want to deploy to:


FastAPI Cloud

📁 Setting up and deploying /Users/xxxx/Documents/project/fastapi-cloud-demo

🏢 Select the team you want to deploy to:
Filter:

● John Doe

This is our first deployment, so we will create a new app.

 📦 Do you want to create a new app?
● Yes ○ No

Write the app name or press Enter to use the suggested name:

 ✏️ What's your app name?
fastapi-cloud-demo

The CLI asks where pyproject.toml lives. In our demo project, it is in the root. So, we will leave the field blank and press Enter.

 📂 Directory where your app's pyproject.toml file lives (e.g. src, backend):
Leave empty if pyproject.toml is in the current directory

Review the deployment summary

 📋 Deployment configuration:

Team: John Doe
App name: fastapi-cloud-demo
Directory: .

👀 Does everything look right?
● Yes, start the deployment!
○ No, let me start over

Build complete!


🐔 App created successfully! App slug: fastapi-cloud-demo-xxxxxx

🚀 Deploying app...

🚀 Build complete!

✅ Ready the chicken! 🐔

Your app is ready at https://fastapi-cloud-demo-xxxxxx.fastapicloud.dev

4. Verify the deployed app

I used the same /health check from earlier, this time with the URL FastAPI Cloud printed in my terminal. Replace DEPLOYED_APP_URL with yours.

curl -fsS DEPLOYED_APP_URL/health

You should get {"status":"ok"} back. Also, you can open /docs at the same URL to try the API in your browser.

If the build fails, check the terminal output.
If the deploy finishes but /health fails, check the runtime logs in the FastAPI Cloud dashboard.

5. After the first deploy

The app is live, and I’m happy to stop here for a demo. If I keep it running, here’s what I’d look at next.

Get İnan DELİBAŞ’s stories in your inbox

Join Medium for free to get updates from this writer.

Continuous deployment (CD): How do I ship the next change without running the deploy command by hand? GitHub integration

Environment variables: I’d set the database host and credentials through the app’s environment variables. Environment variables

Scaling: I’d check how the app scales up when traffic picks up and back down when things get quiet. Autoscaling

Custom domains: I’d give the API an address of its own, like api.example.com.Custom domains

Observability: Once people start using the API, I’d watch request volume, response times, and errors. Metrics

Logs: If a build fails, I’d open the build logs. If a request fails after deploy, I’d start with the runtime logs. Build and runtime logs

--

--

İnan DELİBAŞ
İnan DELİBAŞ

Written by İnan DELİBAŞ

Senior Backend Engineer | Python | Distributed Systems & Microservices | Writing about backend engineering and real-world technical challenges