{
  "openapi": "3.0.1",
  "info": {
    "title": "RunGate — Cost Forecast & Budget Guard for Apify Tasks",
    "description": "Forecast Task cost and duration before execution, return ALLOW/WARN/BLOCK, and start approved runs with native Apify charge and timeout caps.",
    "version": "0.0",
    "x-build-id": "d6OmkrvX2W6TflGVZ"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/jernside~rungate-cost-guard/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-jernside-rungate-cost-guard",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/jernside~rungate-cost-guard/runs": {
      "post": {
        "operationId": "runs-sync-jernside-rungate-cost-guard",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/jernside~rungate-cost-guard/run-sync": {
      "post": {
        "operationId": "run-sync-jernside-rungate-cost-guard",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "required": [
          "targetTaskId",
          "apifyToken"
        ],
        "properties": {
          "targetTaskId": {
            "title": "Target Task ID",
            "minLength": 3,
            "type": "string",
            "description": "Paste the Task ID or username~task-name from the Task API tab. Example: your-username~daily-product-scraper."
          },
          "apifyToken": {
            "title": "Scoped Apify API token",
            "type": "string",
            "description": "Used only to read and start the target Task. The value is encrypted by Apify and never written to logs or output."
          },
          "mode": {
            "title": "Operating mode",
            "enum": [
              "monitor_only",
              "automatic"
            ],
            "type": "string",
            "description": "Monitor only analyzes the Task without starting it. Automatic guard starts only runs permitted by the policy.",
            "default": "monitor_only"
          },
          "monthlyBudgetUsd": {
            "title": "Monthly Task budget",
            "minimum": 0.01,
            "type": "number",
            "description": "Maximum monthly spend in USD for this target Task.",
            "default": 100
          },
          "maxRunCostUsd": {
            "title": "Maximum cost per run",
            "minimum": 0.01,
            "type": "number",
            "description": "RunGate blocks a run when the predicted upper range exceeds this value. The same value is applied as Apify's native maximum-charge cap when a run starts.",
            "default": 5
          },
          "maxDurationMinutes": {
            "title": "Maximum run duration",
            "minimum": 1,
            "maximum": 1440,
            "type": "integer",
            "description": "RunGate blocks historically longer jobs and applies this value as the target run timeout.",
            "default": 60
          },
          "riskTolerance": {
            "title": "Risk tolerance",
            "enum": [
              "strict",
              "balanced",
              "permissive"
            ],
            "type": "string",
            "description": "Strict blocks weak history and Task changes. Balanced warns. Permissive keeps more runs eligible.",
            "default": "balanced"
          },
          "warnAction": {
            "title": "Automatic action on WARN",
            "enum": [
              "block",
              "allow"
            ],
            "type": "string",
            "description": "Used only in Automatic guard mode. Blocking WARN results is the safest default.",
            "default": "block"
          },
          "lookbackRuns": {
            "title": "Recent runs to analyze",
            "minimum": 5,
            "maximum": 200,
            "type": "integer",
            "description": "Number of recent target Task runs used for cost and duration estimates.",
            "default": 30
          },
          "minHistoryRuns": {
            "title": "Minimum successful runs",
            "minimum": 3,
            "maximum": 50,
            "type": "integer",
            "description": "Minimum completed runs required before the estimate is considered established.",
            "default": 5
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}