How to create a flow run from a deployment with REST API via http client

Sometimes it can be useful to create flow runs using only HTTP calls (no Prefect environment, or even python environment) - for example, when you want to trigger a flow run from an AWS Lambda without installing Prefect in the Lambda runtime.

Here’s an example of how to create a flow run from an existing deployment using an HTTP client like Python’s httpx.

import os

import httpx

api_url = os.getenv('PREFECT_API_URL')
headers = {
  "Authorization": f"Bearer {os.getenv('PREFECT_API_KEY')}"
}
payload = {
  "name": "my-new-flow-run-name", # not required
  #"parameters": {} only required if your flow needs params
}
deployment_id = "<my-deployment-uuid>"

async with httpx.AsyncClient() as client:
  response = await client.post(
    f"{api_url}/deployments/{deployment_id}/create_flow_run",
    headers=headers,
    json=payload
  )
  response.raise_for_status()
1 Like

Tested and working like a charm. Thanks you!

1 Like