Joshua Caskie
10/21/2025, 7:50 PMprefect cloud loginMarvin
10/21/2025, 7:50 PMNate
10/21/2025, 7:51 PMPREFECT_API_URL (and PREFECT_API_KEY if using cloud) and that's ultimately what prefect cloud login does, via your profileMarvin
10/21/2025, 7:53 PMprefect cloud login.
The most common options:
- Environment variables (recommended; highest precedence)
- Set both:
- PREFECT_API_URL = https://api.prefect.cloud/api/accounts/<ACCOUNT_ID>/workspaces/<WORKSPACE_ID>
- PREFECT_API_KEY = your user or service account API key
- Example:
export PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/<ACCOUNT_ID>/workspaces/<WORKSPACE_ID>>"
export PREFECT_API_KEY="pnu_XXXXXXXXXXXXXXXX"
- Note: There are no separate `PREFECT_CLOUD_ACCOUNT_ID`/`WORKSPACE_ID` settings in 3.x; IDs are embedded in PREFECT_API_URL. You can copy IDs from the app URL: https://app.prefect.cloud/account/<ACCOUNT_ID>/workspace/<WORKSPACE_ID>/...
- Profiles (persist settings without a login flow)
- Create/use a profile and set values:
prefect profile create cloud-noninteractive
prefect profile use cloud-noninteractive
prefect config set api.url="<https://api.prefect.cloud/api/accounts/<ACCOUNT_ID>/workspaces/<WORKSPACE_ID>>" api.key="pnu_XXXXXXXXXXXXXXXX"
- You can inspect with:
prefect profile inspect
- Programmatic (for short-lived contexts)
from prefect.settings import PREFECT_API_KEY, PREFECT_API_URL
from prefect.settings.context import temporary_settings
with temporary_settings({
PREFECT_API_URL: "<https://api.prefect.cloud/api/accounts/<ACCOUNT_ID>/workspaces/<WORKSPACE_ID>>",
PREFECT_API_KEY: "pnu_XXXXXXXXXXXXXXXX",
}):
# your Prefect code here
pass
Workers/containers/CI
- For pull-based workers (Docker/Kubernetes/VMs), set PREFECT_API_URL and PREFECT_API_KEY as container or pod env vars (ideally via secrets). This is all that’s needed to connect to your Cloud workspace.
- Prefer service account API keys for non-user automation.
Helpful docs:
- Connect to Prefect Cloud
- Settings and profiles overview
- API keys
- Service accounts
- Manage settings
If you share where you’re running (local, Docker, Kubernetes, or CI), I can give a drop-in example for that environment.