Seb
11/13/2025, 11:09 AMMarvin
11/13/2025, 11:09 AMMarvin
11/13/2025, 11:14 AMflow.deploy() doesn’t take a headers argument, in Prefect 3.x you can add custom HTTP headers to every API request (including deploy) via client settings.
Ways to set them:
- Environment variable (applies to the current process)
export PREFECT_CLIENT_CUSTOM_HEADERS='{"X-My-Header":"foo","X-Another":"bar"}'
Then run your deployment code or CLI and Prefect will include these headers on all API calls.
- Profile TOML (persistent across sessions)
In your profile (e.g., ~/.prefect/profiles.toml or a project prefect.toml):
[client.custom_headers]
X-My-Header = "foo"
X-Another = "bar"
- Programmatic (for your own client usage)
If you create a client yourself, you can pass httpx settings:
from prefect.client.orchestration import PrefectClient
client = PrefectClient(
api="<https://api.prefect.cloud>",
httpx_settings={"default_headers": {"X-My-Header": "foo"}}
)
Note: flow.deploy() uses the default client from current settings; it doesn’t accept httpx_settings directly. If you need headers for deploy, prefer the env var or profile settings above.
Example with deploy in code (env var set first):
import os
os.environ["PREFECT_CLIENT_CUSTOM_HEADERS"] = '{"X-My-Header":"foo"}'
from prefect import flow
@flow
def my_flow():
return "hi"
# Your normal deployment call — headers will be included automatically
my_flow.from_source(
"<https://github.com/owner/repo>",
entrypoint="flows/my_flow.py:my_flow"
).deploy(
name="my-deployment",
work_pool_name="my-pool"
)
Notes:
- Headers you set are merged with Prefect’s own headers; Prefect may manage some reserved headers for functionality and security.
- The same setting applies to prefect deploy from the CLI.
Docs:
- Settings reference (see client.custom_headers)
- Settings and profiles
- Client API
If you can share which header you need (e.g., a proxy or gateway requirement), I can suggest the cleanest setup for your environment.