Hi <@ULVA73B9P>, how to connect prefect using self...
# ask-marvin
p
Hi @Marvin, how to connect prefect using self host api?
m
thought for 310.9 seconds
Great question! Assuming you’re on Prefect 3.x, you connect your CLI, flows, and workers to a self‑hosted Prefect API by pointing them at your server’s
/api
endpoint via
PREFECT_API_URL
. Quick start: 1) Start your self-hosted server
Copy code
prefect server start
# UI at <http://127.0.0.1:4200>, API at <http://127.0.0.1:4200/api>
2) Point Prefect to your server - One-off for current shell:
Copy code
export PREFECT_API_URL="<http://127.0.0.1:4200/api>"
- Or persist it in a profile:
Copy code
prefect profile create self-hosted
prefect profile use self-hosted
prefect config set PREFECT_API_URL="<http://127.0.0.1:4200/api>"
3) Verify the connection
Copy code
prefect config view --show-sources
prefect flow ls
Workers pick it up the same way:
Copy code
# Using active profile value
prefect worker start -p my-pool

# Or override inline
PREFECT_API_URL="<http://server:4200/api>" prefect worker start -p my-pool
Python example:
Copy code
from prefect.client.orchestration import get_client
import asyncio

async def main():
    async with get_client() as client:
        flows = await client.read_flows()
        print(f"Found {len(flows)} flows")

asyncio.run(main())
Tip for containers: inside Docker/Compose/K8s, don’t use localhost. Use the service DNS name:
Copy code
# docker-compose example
environment:
  PREFECT_API_URL: <http://prefect-server:4200/api>
Troubleshooting: - “No Prefect API URL provided”: set it with
prefect config set PREFECT_API_URL="http://<host>:4200/api"
and re-run
prefect config view --show-sources
. - Connection issues: ensure the server is running and reachable from the client/worker host and port. Would you share a bit more about your setup? - Prefect version (2.x or 3.x)? - Where is your server running (local, Docker, Kubernetes, remote VM)? - Are you connecting from your laptop, a container, or another machine?