{
  "id": "fXtw0Iqzc5X1fyPf",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Generate Summaries From Uploaded Files",
  "tags": [],
  "nodes": [
    {
      "id": "e8d5aaf3-8ef3-4b66-8d61-1a8eedde36ca",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        140,
        100
      ],
      "parameters": {
        "path": "2c3f820b-8b84-41d8-bc1a-1e33f9bb7bfd",
        "options": {},
        "formTitle": "Upload Form",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "File",
              "multipleFiles": false,
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d7817690-47d2-491d-8819-373bb5402daf",
      "name": "Create Thread",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        540,
        100
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/threads",
        "options": {},
        "requestMethod": "POST",
        "authentication": "headerAuth",
        "jsonParameters": true,
        "bodyParametersJson": "={\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Summarize the attached file.\",\n      \"attachments\": [\n        {\n          \"file_id\": \"{{$node['Upload File'].json['id']}}\",\n          \"tools\": [ { \"type\": \"file_search\" } ]\n        }\n      ]\n    }\n  ]\n}",
        "headerParametersJson": "{\n  \"OpenAI-Beta\": \"assistants=v2\"\n}"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5b93297d-c354-410a-a19e-5f7e3993ba32",
      "name": "Poll Run Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        140,
        320
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/threads/{{$node[\"Create Thread\"].json[\"id\"]}}/runs/{{$node[\"Run Assistant\"].json[\"id\"]}}",
        "options": {},
        "authentication": "headerAuth",
        "headerParametersUi": {
          "parameter": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d6b28a0e-1468-4dbc-b193-7a7f5b6c7e99",
      "name": "Is Not Complete?",
      "type": "n8n-nodes-base.if",
      "position": [
        340,
        320
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $node[\"Poll Run Status\"].json[\"status\"] }}",
              "value2": "completed",
              "operation": "notEqual"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "88db0070-35f4-4fd7-9e51-8a30bd18bc23",
      "name": "Wait 2s",
      "type": "n8n-nodes-base.wait",
      "position": [
        540,
        300
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 2
      },
      "typeVersion": 1
    },
    {
      "id": "9ea51b21-08e3-4a28-b8f5-fd85758e46f9",
      "name": "Fetch Summary",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        720,
        340
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/threads/{{$node[\"Create Thread\"].json[\"id\"]}}/messages",
        "options": {},
        "authentication": "headerAuth",
        "jsonParameters": true,
        "headerParametersJson": "{\n  \"OpenAI-Beta\": \"assistants=v2\"\n}"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "14fdac82-a66a-493e-a8ed-74bdda5ea316",
      "name": "Run Assistant",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        720,
        100
      ],
      "parameters": {
        "url": "=https://api.openai.com/v1/threads/{{$node[\"Create Thread\"].json[\"id\"]}}/runs",
        "method": "POST",
        "options": {},
        "jsonBody": "{\n  \"assistant_id\": \"REPLACE_WITH_YOUR_ASSISTANT_ID\",\n  \"instructions\": \"You are an AI knowledge-base assistant.\\n\\nFor every file provided (PDF, DOCX, slides, or an audio/video transcript) return a single, valid JSON object with exactly these keys:\\n{\\n  \\\"title\\\": string,\\n  \\\"summary\\\": string,\\n  \\\"bullets\\\": string[],\\n  \\\"tags\\\": string[]\\n}\\n\u2022 Read or transcribe the entire file first.\\n\u2022 Do not add any extra keys, comments, or explanatory text.\\n\u2022 If the file is audio or video, transcribe it before summarizing.\\n\u2022 If the file type is unsupported (e.g., pure image), reply with:\\n  { \\\"error\\\": \\\"unsupported_file_type\\\" }\\n\u2022 Return **only** the JSON object\u2014nothing else.\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "fabdc95f-4bfd-41c3-8f1b-3b74ee6513fd",
      "name": "Upload File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        340,
        100
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/files",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "File"
            },
            {
              "name": "purpose",
              "value": "assistants"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a9a89fc0-37bf-43ba-bae3-97b159f84a27",
  "connections": {
    "Wait 2s": {
      "main": [
        [
          {
            "node": "Poll Run Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload File": {
      "main": [
        [
          {
            "node": "Create Thread",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Thread": {
      "main": [
        [
          {
            "node": "Run Assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Assistant": {
      "main": [
        [
          {
            "node": "Poll Run Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll Run Status": {
      "main": [
        [
          {
            "node": "Is Not Complete?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Not Complete?": {
      "main": [
        [
          {
            "node": "Wait 2s",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fetch Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Upload File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}