{
  "openapi": "3.0.1",
  "info": {
    "title": "Push AI API",
    "description": "Programmatic access to Push AI agents. Create API keys in the Push AI dashboard, then use them to list agents, invoke runs, and poll for results.",
    "version": "1.0.0",
    "contact": {
      "name": "Push AI Support",
      "email": "support@push.ai"
    }
  },
  "servers": [
    {
      "url": "https://api.push.ai/api/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/agents": {
      "get": {
        "operationId": "listAgents",
        "summary": "List agents",
        "description": "Returns all published agents for your organization, with their accepted parameters.",
        "tags": ["Agents"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of agents to return (1\u2013100).",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Number of agents to skip for pagination.",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A paginated list of published agents.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAgentsResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/agents/{agent_id}/runs": {
      "post": {
        "operationId": "createRun",
        "summary": "Create a run",
        "description": "Invoke a published agent asynchronously. Returns a run ID that you can poll for status and results.\n\nPass `?dry_run=true` to preview the compiled prompt without executing.",
        "tags": ["Runs"],
        "parameters": [
          {
            "name": "agent_id",
            "in": "path",
            "required": true,
            "description": "The ID of the agent to invoke.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "dry_run",
            "in": "query",
            "required": false,
            "description": "If `true`, returns the compiled prompt and parameters without executing the agent.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRunRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Run accepted and queued for execution.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateRunResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request \u2014 unknown parameter, invalid value, or bad agent configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Agent not found, not published, or does not belong to your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/agents/{agent_id}/runs/{run_id}": {
      "get": {
        "operationId": "getRunStatus",
        "summary": "Get run status",
        "description": "Poll for the status and result of an agent run. Returns the output when the run succeeds, or an error message if it fails.",
        "tags": ["Runs"],
        "parameters": [
          {
            "name": "agent_id",
            "in": "path",
            "required": true,
            "description": "The ID of the agent that owns the run.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "run_id",
            "in": "path",
            "required": true,
            "description": "The run ID returned by the create run endpoint.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current run status and result (if complete).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RunStatusResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Run not found or does not belong to your organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Organization API key. Create one in the Push AI dashboard under Settings \u2192 API Keys."
      }
    },
    "schemas": {
      "ExternalAgent": {
        "type": "object",
        "required": ["id", "name", "parameters"],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique agent identifier."
          },
          "name": {
            "type": "string",
            "description": "Human-readable agent name."
          },
          "description": {
            "type": "string",
            "nullable": true,
            "description": "Optional agent description."
          },
          "parameters": {
            "type": "array",
            "description": "Parameters the agent accepts at invocation time.",
            "items": {
              "$ref": "#/components/schemas/AgentParameter"
            }
          }
        }
      },
      "AgentParameter": {
        "type": "object",
        "required": ["name", "required"],
        "properties": {
          "name": {
            "type": "string",
            "description": "Parameter name. Use this in the `parameter_bindings` array when creating a run."
          },
          "required": {
            "type": "boolean",
            "description": "Whether this parameter must be provided."
          },
          "description": {
            "type": "string",
            "nullable": true,
            "description": "Human-readable description of what this parameter controls."
          }
        }
      },
      "PaginationMeta": {
        "type": "object",
        "required": ["total", "limit", "offset"],
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of results across all pages."
          },
          "limit": {
            "type": "integer",
            "description": "Maximum results per page."
          },
          "offset": {
            "type": "integer",
            "description": "Number of results skipped."
          }
        }
      },
      "ListAgentsResponse": {
        "type": "object",
        "required": ["agents", "pagination"],
        "properties": {
          "agents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ExternalAgent"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationMeta"
          }
        }
      },
      "ParameterBinding": {
        "type": "object",
        "required": ["name", "value"],
        "properties": {
          "name": {
            "type": "string",
            "description": "The parameter name (must match a name from the agent's `parameters` list)."
          },
          "value": {
            "type": "string",
            "description": "The value to bind to this parameter (e.g. a dimension value name like `\"Acme Corp\"`)."
          }
        }
      },
      "CreateRunRequest": {
        "type": "object",
        "properties": {
          "parameter_bindings": {
            "type": "array",
            "nullable": true,
            "description": "Optional parameter values to bind for this run. Each entry maps a parameter name to a value.",
            "items": {
              "$ref": "#/components/schemas/ParameterBinding"
            }
          }
        }
      },
      "CreateRunResponse": {
        "type": "object",
        "required": ["run_id", "status"],
        "properties": {
          "run_id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique run identifier. Use this to poll for status."
          },
          "status": {
            "type": "string",
            "enum": ["pending"],
            "description": "Initial status of the queued run."
          }
        }
      },
      "RunStatusResponse": {
        "type": "object",
        "required": ["run_id", "status", "created_at"],
        "properties": {
          "run_id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique run identifier."
          },
          "status": {
            "type": "string",
            "enum": ["running", "succeeded", "failed", "cancelled"],
            "description": "Current run status."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the run was created."
          },
          "completed_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "When the run finished. `null` if still running."
          },
          "output": {
            "type": "string",
            "nullable": true,
            "description": "The agent's final output. Only present when status is `succeeded`."
          },
          "error": {
            "type": "string",
            "nullable": true,
            "description": "Error message. Only present when status is `failed`."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message", "request_id"],
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code (e.g. `invalid_api_key`, `agent_not_found`)."
              },
              "message": {
                "type": "string",
                "description": "Human-readable error description."
              },
              "request_id": {
                "type": "string",
                "description": "Unique request identifier for debugging. Also returned in the `X-Request-Id` response header."
              }
            }
          }
        }
      }
    }
  }
}
