{
  "name": "Document Translator via LLM",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "doc-translate",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "dt0001-0001-4000-8000-000000000001",
      "name": "Receive Translation Request",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "url": "={{ $json.body.documentUrl }}",
        "options": {
          "responseType": "arraybuffer",
          "timeout": 60000
        }
      },
      "id": "dt0001-0002-4000-8000-000000000002",
      "name": "Fetch Document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [460, 300]
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "id": "dt0001-0003-4000-8000-000000000003",
      "name": "Extract Document Text",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "Translate the following document text into {{ $('Receive Translation Request').item.json.body.targetLanguage }}. Preserve the original formatting, structure, headings, and paragraph breaks as closely as possible. Only translate — do not summarize or omit content.\n\nDocument:\n{{ $json.text }}"
            }
          ]
        },
        "options": {
          "temperature": 0.2,
          "maxTokens": 4096
        }
      },
      "id": "dt0001-0004-4000-8000-000000000004",
      "name": "Translate Document",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [900, 300]
    },
    {
      "parameters": {
        "jsCode": "const translation = $input.item.json.message.content;\nconst targetLang = $('Receive Translation Request').item.json.body.targetLanguage;\nconst originalUrl = $('Receive Translation Request').item.json.body.documentUrl;\nreturn [{ json: { translation, targetLanguage: targetLang, sourceDocument: originalUrl, wordCount: translation.split(' ').length, translatedAt: new Date().toISOString() } }];"
      },
      "id": "dt0001-0005-4000-8000-000000000005",
      "name": "Build Translation Output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1120, 300]
    }
  ],
  "connections": {
    "Receive Translation Request": {
      "main": [[{ "node": "Fetch Document", "type": "main", "index": 0 }]]
    },
    "Fetch Document": {
      "main": [[{ "node": "Extract Document Text", "type": "main", "index": 0 }]]
    },
    "Extract Document Text": {
      "main": [[{ "node": "Translate Document", "type": "main", "index": 0 }]]
    },
    "Translate Document": {
      "main": [[{ "node": "Build Translation Output", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
