Your FastAPI app calls partner APIs that whitelist one IP, but your host's egress keeps changing. Route httpx and requests through two fixed static EU IPs and stop getting blocked.
Works with httpx, requests, Uvicorn, Gunicorn, Docker, and serverless FastAPI
from fastapi import FastAPI
import httpx, os
app = FastAPI()
# HTTPS_PROXY is read from the env
@app.get("/ip")
async def ip():
async with httpx.AsyncClient() as c:
r = await c.get("https://outboundgateway.com/ip/")
return r.json() # one of your EU IPs
FastAPI itself doesn't control your outbound IP. The platform it runs on does, and that IP is rarely stable.
A FastAPI BackgroundTask fires after the response returns, often from a different worker than the one that handled the request. Its outbound IP is not the one your partner whitelisted, so follow-up calls get rejected.
An async httpx AsyncClient keeps its connection pool open. When the host rotates the egress IP mid-life, half your in-flight requests silently route through an address that the partner API no longer allows.
Production FastAPI runs behind Uvicorn or Gunicorn with several workers. Each worker can land on a different node with a different egress IP, so a single allowlisted IP is not enough to cover your whole app.
FastAPI on AWS Lambda, Vercel, or other serverless runtimes gets a fresh outbound IP on every cold start. Partner APIs that whitelist a single IP see a constantly moving target and block you.
"Send us the IP that will call our API."
You need an answer that is still true tomorrow.
FastAPI app
OutboundGateway
Two fixed EU IPs
Partner API
The partner API sees one of your two fixed EU IPs, on every call, from every worker.
FastAPI services that call partner APIs requiring IP allowlisting.
Background tasks and workers pulling from IP-restricted sources.
Lambda and edge deploys with no native static egress.
Apps that must keep outbound traffic inside the EU.
Set the proxy once. Every outbound call from your FastAPI app goes through it.
FastAPI is async-native, and httpx is its natural HTTP client. Current httpx reads HTTPS_PROXY from the environment automatically, so you only need to set the env var.
# .env
HTTPS_PROXY=https://USER:PASS@eu-01.outboundgateway.com:8443
from fastapi import FastAPI
import httpx
app = FastAPI()
@app.get("/ip")
async def ip():
# httpx picks up HTTPS_PROXY from the environment
async with httpx.AsyncClient() as client:
r = await client.get("https://outboundgateway.com/ip/")
return r.json()
๐ Full guide: for retries, timeouts, and session reuse, see the Python SSL proxy guide.
If your FastAPI app calls a sync client (for example inside a run_in_threadpool block), requests honors HTTPS_PROXY from the environment too.
import requests, os
def call_partner():
# requests reads HTTPS_PROXY from the environment
r = requests.get(
"https://api.partner.example.com/data",
headers={"Authorization": f"Bearer {os.environ['PARTNER_TOKEN']}"},
timeout=30,
)
return r.json()
Load the proxy URL from a .env file so credentials never land in your image.
# .env (add to .dockerignore, never commit)
HTTPS_PROXY=https://USER:PASS@eu-01.outboundgateway.com:8443
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
docker run --rm --env-file .env -p 80:80 my-fastapi-app
When a partner cares where your traffic originates, the location of the egress matters.
Your proxy runs on infrastructure inside the European Union, so outbound traffic stays within EU jurisdiction.
Data handling that aligns with European privacy expectations, for teams that need to keep processing inside the EU.
Traffic is not detoured through US-based servers, which keeps your compliance story simple.
Two fixed IPs give auditors and partners a stable, predictable answer about where requests come from.
A pair of static IPs with automatic failover. Allowlist once, keep working.
httpx and requests pick up HTTPS_PROXY automatically. No bespoke client code.
Set the env var once. Local dev, Docker, CI, and serverless all egress the same way.
No NAT gateway, no VPC changes, no custom networking. Just an environment variable.
TLS passthrough. Your traffic is never decrypted or inspected by the proxy.
Starting from โฌ19/month. Flexible plans for every scale. Cancel anytime.
Stop fighting rotating egress IPs. Give your FastAPI backend two fixed EU IPs today.
Yes. Current versions of httpx read the HTTPS_PROXY environment variable automatically, so you do not need to pass a proxy argument to AsyncClient. Set the env var once and every outbound request from your FastAPI routes and background tasks is routed through it. This is the cleanest way to give a Python app a static outbound IP.
They do, as long as the task uses an HTTP client that respects HTTPS_PROXY (httpx and requests both do). Because the proxy is set at the environment level rather than per call, background tasks fire through the same two fixed EU IPs as your request handlers, which is exactly what partner APIs expect.
Without a proxy, no. A multi-worker Uvicorn or Gunicorn deployment, or a serverless FastAPI on Lambda, can emit from many different IPs. OutboundGateway solves this by giving every worker the same two fixed static EU IPs to egress through, so your partners only ever need to allowlist those two addresses.
We're happy to help you check whether OutboundGateway fits your FastAPI workload.
Contact Our Team →