๐Ÿ‡ช๐Ÿ‡บ Static IP for FastAPI

๐Ÿ‡ช๐Ÿ‡บ Static IP for FastAPI

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

main.py ยท FastAPI + httpx

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

Why FastAPI Apps Get Blocked

FastAPI itself doesn't control your outbound IP. The platform it runs on does, and that IP is rarely stable.

Background tasks egress from the wrong pod

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.

Long-lived httpx pools survive IP rotations

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.

Multi-worker Uvicorn fans out across IPs

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.

Serverless FastAPI has no fixed egress at all

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.

When a partner asks for your IP

"Send us the IP that will call our API."

You need an answer that is still true tomorrow.

Route FastAPI Through a Static IP Proxy

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.

  • Set once in your environment, applies to every route and every background task.
  • No code changes to your endpoints, just the HTTP client config.
  • Two IPs with automatic failover, so a problem on one never drops your calls.

Why FastAPI Teams Choose This

  • A pair of fixed EU IPs that your partners can allowlist once and forget.
  • Idiomatic for async Python, works with httpx and requests out of the box.
  • Same two fixed IPs across local dev, CI, Docker, and serverless deploys.
  • EU-hosted egress, GDPR-aligned, with no traffic leaving EU jurisdiction.

Designed For

SaaS backends

FastAPI services that call partner APIs requiring IP allowlisting.

Async data pipelines

Background tasks and workers pulling from IP-restricted sources.

Serverless FastAPI

Lambda and edge deploys with no native static egress.

EU-regulated teams

Apps that must keep outbound traffic inside the EU.

How It Works

Set the proxy once. Every outbound call from your FastAPI app goes through it.

Option 1: httpx (async, recommended)

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.

Option 2: requests (sync)

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()

Option 3: Docker / Uvicorn

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

Built for European Python Teams

When a partner cares where your traffic originates, the location of the egress matters.

EU-hosted egress

Your proxy runs on infrastructure inside the European Union, so outbound traffic stays within EU jurisdiction.

GDPR-aligned

Data handling that aligns with European privacy expectations, for teams that need to keep processing inside the EU.

No US routing

Traffic is not detoured through US-based servers, which keeps your compliance story simple.

Clear outbound identity

Two fixed IPs give auditors and partners a stable, predictable answer about where requests come from.

Why Developers Choose OutboundGateway

Two fixed EU IPs

A pair of static IPs with automatic failover. Allowlist once, keep working.

Native Python support

httpx and requests pick up HTTPS_PROXY automatically. No bespoke client code.

One config

Set the env var once. Local dev, Docker, CI, and serverless all egress the same way.

No infra surgery

No NAT gateway, no VPC changes, no custom networking. Just an environment variable.

HTTPS-only

TLS passthrough. Your traffic is never decrypted or inspected by the proxy.

Production-ready

Starting from โ‚ฌ19/month. Flexible plans for every scale. Cancel anytime.

Get a Static IP for Your FastAPI App

Stop fighting rotating egress IPs. Give your FastAPI backend two fixed EU IPs today.

Frequently Asked Questions

Does FastAPI's httpx client honor HTTPS_PROXY?

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.

Do FastAPI BackgroundTasks go through the proxy too?

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.

Will a single allowlisted IP work for my whole FastAPI deployment?

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.

Still Deciding?

We're happy to help you check whether OutboundGateway fits your FastAPI workload.

Contact Our Team →