Sites and apps
How to put a FastAPI API online
In short
To put a FastAPI API online, list fastapi and uvicorn in requirements.txt, run uvicorn on 0.0.0.0 with the port from the PORT variable, and upload the code. Netrun detects Python, builds the project and gives you an HTTPS link, and the interactive docs open at /docs. You do not need your own server, nginx or a manually issued certificate.
- For a FastAPI app to accept requests from the internet, it needs the uvicorn application server listed in requirements.txt alongside fastapi.
- Uvicorn listens on 127.0.0.1 by default, and the app is reachable from outside only when it runs on 0.0.0.0.
- Netrun passes the port to the app through the PORT environment variable, so the port number does not belong in the code.
- FastAPI serves interactive documentation at /docs and an alternative version at /redoc out of the box.
- On the Netrun Free plan an API sleeps when there are no requests and wakes on the first one, so the first response after a pause arrives a few seconds later.
Normally, to open up your FastAPI API to the internet, you have to rent a VPS, install Python on it, figure out uvicorn, set up nginx as a proxy, issue and keep renewing an SSL certificate, and then make sure the process does not die after a reboot. For a pet project or your first service, that is hours of fiddling with things that have nothing to do with your actual code.
Netrun takes that infrastructure off your hands: you upload your code, the platform figures out on its own that it is a Python project, builds it, and hands you a public link with HTTPS. No server, no nginx, no manual certificate. Here is how to put your API online in a few minutes.
Put together requirements.txt#
Add a requirements.txt file to the root of your project and list your dependencies in it — at minimum fastapi and uvicorn. uvicorn is the server that runs your async FastAPI app and accepts requests. Netrun uses this file to know what to install. You do not need to include a venv folder with the libraries themselves — the platform installs them for you.
Listen on the port from an environment variable#
Start uvicorn so that it listens on host 0.0.0.0 and the port that Netrun passes through an environment variable (the platform forwards the right port for you). Do not hardcode the port as a number in your code — read it from the environment, for example via os.environ. That way your API becomes reachable at the link you are given.
Move secrets into environment variables#
Do not keep third-party service keys, tokens, or your database connection string in your code — read them from environment variables. When you set up the project, Netrun asks for these values and injects them into the environment, so your secrets never end up in the repository or leak out with your code.
Upload your code to Netrun#
Upload your project as a ZIP archive or import it from a GitHub repository, including a private one. Netrun detects that it is Python and builds the app automatically — you do not need to specify the language or write a Dockerfile. Build progress and logs are visible in your dashboard in real time.
Check the API and the auto-generated docs#
When the build finishes, a public HTTPS link appears in your dashboard. FastAPI serves interactive auto-generated docs at /docs — open it in your browser to see every endpoint and send test requests right there. If the API responds, it is working.
That is it: your FastAPI API is online behind a secure link, with no server of your own and no nginx setup. On the Free plan a web app sleeps when idle and wakes on the first request — that first request is a little slower, but the project costs nothing while idle. If your API needs to respond instantly with no pauses, a paid plan with always-on running is a better fit. If something fails, Netrun restarts the project on its own, and the logs and status are always visible in your dashboard. Try Netrun.
Common questions
How do I start uvicorn so it reads the port from the environment?
For example, with uvicorn main:app --host 0.0.0.0 --port $PORT, or from the code: uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 8000))). The key part is not using 127.0.0.1: that address is reachable only from inside the server, so the public link will not open.
Why does the link show an error when the API works locally?
Most often the app listens on localhost or on a hardcoded port. Check that uvicorn runs on 0.0.0.0 and takes the port from the PORT variable, and that every dependency is listed in requirements.txt. The error details are in the logs in your dashboard.
Can I hide /docs from the public?
Yes, FastAPI handles that itself: pass docs_url=None and redoc_url=None when you create the app, and the documentation pages stop opening. It is handy to switch them on with an environment variable only where you need them.
Where should the API keep its database?
If the API writes to SQLite, put the database file in the persistent /data folder: everything there survives code updates and restarts, while files outside /data disappear on the next publish. PostgreSQL can be an external database connected through a connection string in secrets, or a service in your own docker-compose.
Is the Free plan enough for an API that a frontend calls?
For a study project or a demo, yes: the API sleeps without requests and wakes on the first one, so the first response after a pause just takes a few seconds longer. If the API has to answer instantly at any moment, the Pro plan keeps the project from sleeping.