# Prefect

The Prefect template is designed to create a new execution of type **Flow**. To use this template, specific variables and secrets must be pre-configured in your environment.

## **Prerequisites**

Before proceeding with the template configuration, the following must be set up in the environment:

* **Variables**:
  * **`prefect_api_version`**: Specifies the Prefect API version being used.
  * **`prefect_flow_id`**: Identifies the Prefect Flow to be executed.
* **Secrets**:
  * **`prefect_api_key`**: Authentication token for secure access to the Prefect API.

### Additional Requirements for Prefect Cloud

For users on the **Cloud** version of Prefect, the following additional variables are required:

* **`prefect_account_id`**: Identifier for your Prefect account.
* **`prefect_workspace_id`**: Identifier for the specific Prefect workspace being used.

## Triggering a flow

When a registered job in Erathos successfully completes, the specified Flow will be triggered.

### Prefect Cloud

POST Payload:

```json
{
  "description": "Create Prefect Cloud flow run",
  "is_active": true,
  "method": "POST",
  "url": "https://api.prefect.cloud/api/accounts/${{variables.account_id}}/workspaces/${{variables.workspace_id}}/flow_runs/",
  "header": {
    "Content-Type": "application/json",
    "Authorization": "Bearer ${{secrets.prefect_api_key}}"
    "x-prefect-api-version": "${{variables.prefect_api_version}}"
  },
  "body": {
    "name": "erathos_run_${{erathos.table_name}}"
    "flow_id": "${{variables.prefect_flow_id}}",
    "idempotency_key": "${{erathos.execution_id}}"
  },
  "rules": [
  ],
  "jobs": [
    "<ERATHOS_JOB_ID>",
  ]
}
```

### Self-hosted

```json
{
  "description": "Create Self-hosted Prefect flow run",
  "is_active": true,
  "method": "POST",
  "url": "https://${{variables.prefect_api_url}}/api/flow_runs/",
  "header": {
    "Content-Type": "application/json",
    "Authorization": "Bearer ${{secrets.prefect_api_key}}"
    "x-prefect-api-version": "${{variables.prefect_api_version}}"
  },
  "body": {
    "name": "erathos_run_${{erathos.table_name}}"
    "flow_id": "${{variables.prefect_flow_id}}",
    "idempotency_key": "${{erathos.execution_id}}"
  },
  "rules": [
  ],
  "jobs": [
    "<ERATHOS_JOB_ID>",
  ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.erathos.com/api/quickstart/prefect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
