You've built an AI agent. It works beautifully on your local machine. Now you need to put it somewhere buyers can actually use it. Railway is one of the simplest platforms for deploying Python-based AI agents — especially FastAPI apps — with a generous free tier and a dead-simple deployment workflow.
Here's a step-by-step guide to getting your agent live on Railway in under 10 minutes.
Step 1: Set Up Your Railway Account
Go to railway.app and sign up. You can authenticate with GitHub, which makes the rest of the process seamless. The free tier includes $5 of credit monthly — enough to run a small agent 24/7 with room to spare.
After signing in, you'll land on the Railway dashboard. This is where you'll manage all your projects.
Step 2: Prepare Your Agent for Deployment
Railway expects a few things from your codebase. Here's what your project needs:
A requirements.txt file listing all Python dependencies. If you're using FastAPI, this should include:
fastapi
uvicorn
openai # or your preferred LLM provider SDK
python-dotenv
httpx
A Procfile telling Railway how to start your app. Create a file named Procfile (no extension) in your project root with:
web: uvicorn main:app --host 0.0.0.0 --port $PORT
Replace main:app with your actual module and FastAPI app variable name. The $PORT environment variable is automatically set by Railway.
An .env.example file listing the environment variables your agent needs (without actual values):
OPENAI_API_KEY=
DATABASE_URL=
Step 3: Connect Your GitHub Repo
From the Railway dashboard, click "New Project" → "Deploy from GitHub repo". Railway will ask you to authorize GitHub access if you haven't already.
Select the repository containing your agent. Railway will automatically detect that it's a Python project and start the build process.
If you prefer not to connect a GitHub repo, you can also use the Railway CLI (railway up) to deploy directly from your local machine.
Step 4: Configure Environment Variables
Go to your project dashboard and click the "Variables" tab. Add each environment variable your agent needs. This is where you'll put your API keys, database URLs, and any other secrets.
Never commit secrets to your repository. Railway's environment variable system keeps them secure and separate from your codebase. The .env.example tells other developers what variables are needed, but the actual values live only in Railway.
At minimum, your agent probably needs an OPENAI_API_KEY (or equivalent) and any database connection strings.
Step 5: Deploy and Verify
With your repo connected and environment variables set, Railway will automatically trigger a deployment. You can watch the build logs in real-time. The first deployment takes a minute or two as Railway installs dependencies and builds the container.
Once the build completes, Railway assigns your agent a .railway.app subdomain (e.g., my-agent.up.railway.app). Click the URL to verify your agent is running.
Test it with a quick curl command:
curl https://my-agent.up.railway.app/health
If you see a successful response, your agent is live.
Step 6: Set Up a Custom Domain (Optional)
For a professional listing, you'll want a custom domain. From the project dashboard, go to "Settings" → "Domains". You can either:
- Purchase a domain through Railway's integrated domain provider
- Add an existing domain by pointing its CNAME record to your Railway project's domain
Railway automatically provisions SSL certificates through Let's Encrypt, so your agent will be served over HTTPS — essential for a trustworthy listing.
Step 7: Monitor with Logs
Once deployed, keep an eye on your agent's health through Railway's built-in logging. The "Deployments" tab shows deployment history and status. The "Observability" section shows real-time logs, which are invaluable for debugging.
You can set up alerts for deployment failures, high CPU usage, or other metrics that indicate your agent needs attention.
Best Practices for Railway Deployments
- Use health check endpoints. Add a
/healthroute to your FastAPI app that returns 200. This lets Railway (and your buyers) know your agent is running properly. - Pin your Python version. Add a
runtime.txtfile withpython-3.11to avoid surprises when Railway updates its default Python version. - Set up automatic deploys. Railway can auto-deploy when you push to a specific branch. This makes updates seamless.
- Use Railway's PostgreSQL plugin. If your agent needs a database, Railway offers one-click PostgreSQL provisioning with automatic backups.
Common Gotchas
- Port binding. Your app must listen on the port specified by the
$PORTenvironment variable, not a hardcoded port. - Build failures. If your deployment fails, check that all dependencies are listed in
requirements.txtand that your Python version is compatible. - Free tier limits. Railway's free tier is generous but has limits: $5 of usage per month, projects sleep after periods of inactivity (can be disabled on paid plans).
From Deploy to Sale
Once your agent is deployed on Railway and accessible via a public URL, you're ready to list it on AgentMarket. Include the URL in your listing so buyers can test the agent before purchasing. A live, working demo is the single strongest selling point you can offer.
← Back to all articles