{
  "id": "gptoss20bhf00001",
  "name": "GPT-OSS-20B HuggingFace",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        0
      ],
      "id": "a1b2c3d4-chat-trig-0001-abcdef000001",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://router.huggingface.co/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'openai/gpt-oss-20b:groq', messages: [{ role: 'system', content: 'You are a helpful AI assistant. Always respond in English, regardless of the language of the prompt.' }, { role: 'user', content: $json.chatInput }] }) }}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          },
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        280,
        0
      ],
      "id": "a1b2c3d4-http-req-0002-abcdef000002",
      "name": "Call HuggingFace Inference API",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "caseSensitive": true
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "condition-503-check",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": 503
            },
            {
              "id": "condition-error-check",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ JSON.stringify($json) }}",
              "rightValue": "is currently loading"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        540,
        0
      ],
      "id": "a1b2c3d4-if-node-0003-abcdef000003",
      "name": "Model Loading?"
    },
    {
      "parameters": {
        "amount": 30,
        "unit": "seconds"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        800,
        -100
      ],
      "id": "a1b2c3d4-wait-nod-0004-abcdef000004",
      "name": "Wait 30s for Model"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://router.huggingface.co/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'openai/gpt-oss-20b:groq', messages: [{ role: 'system', content: 'You are a helpful AI assistant. Always respond in English, regardless of the language of the prompt.' }, { role: 'user', content: $('When chat message received').first().json.chatInput }] }) }}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          },
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        1060,
        -100
      ],
      "id": "a1b2c3d4-http-rt-0005-abcdef000005",
      "name": "Retry HuggingFace API",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Parse the HuggingFace OpenAI-compatible API response\nconst data = $input.all();\nconst results = [];\n\nfor (const item of data) {\n  const json = item.json;\n\n  // Handle error responses\n  if (json.error) {\n    results.push({\n      json: {\n        output: `\u26a0\ufe0f HuggingFace API Error: ${json.error.message || JSON.stringify(json.error)}`,\n        model: 'openai/gpt-oss-20b:groq',\n        status: 'error'\n      }\n    });\n    continue;\n  }\n\n  let generatedText = '';\n  if (json.choices && json.choices.length > 0) {\n    generatedText = json.choices[0].message.content;\n  } else {\n    generatedText = JSON.stringify(json, null, 2);\n  }\n\n  results.push({\n    json: {\n      output: generatedText.trim(),\n      model: 'openai/gpt-oss-20b:groq',\n      status: 'success'\n    }\n  });\n}\n\nreturn results;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        100
      ],
      "id": "a1b2c3d4-code-nd-0006-abcdef000006",
      "name": "Parse Response"
    },
    {
      "parameters": {
        "jsCode": "// Parse the retry response (same logic)\nconst data = $input.all();\nconst results = [];\n\nfor (const item of data) {\n  const json = item.json;\n\n  if (json.error) {\n    results.push({\n      json: {\n        output: `\u26a0\ufe0f Model still unavailable after retry: ${json.error.message || JSON.stringify(json.error)}`,\n        model: 'openai/gpt-oss-20b:groq',\n        status: 'error'\n      }\n    });\n    continue;\n  }\n\n  let generatedText = '';\n  if (json.choices && json.choices.length > 0) {\n    generatedText = json.choices[0].message.content;\n  } else {\n    generatedText = JSON.stringify(json, null, 2);\n  }\n\n  results.push({\n    json: {\n      output: generatedText.trim(),\n      model: 'openai/gpt-oss-20b:groq',\n      status: 'success_after_retry'\n    }\n  });\n}\n\nreturn results;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1320,
        -100
      ],
      "id": "a1b2c3d4-code-rt-0007-abcdef000007",
      "name": "Parse Retry Response"
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "Call HuggingFace Inference API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call HuggingFace Inference API": {
      "main": [
        [
          {
            "node": "Model Loading?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Model Loading?": {
      "main": [
        [
          {
            "node": "Wait 30s for Model",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Parse Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 30s for Model": {
      "main": [
        [
          {
            "node": "Retry HuggingFace API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retry HuggingFace API": {
      "main": [
        [
          {
            "node": "Parse Retry Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": [
    {
      "createdAt": "2026-07-16T15:55:54.254120+00:00",
      "updatedAt": "2026-07-16T15:55:54.254132+00:00",
      "id": "558f1e5fcbd7f1ca",
      "name": "Data Transformation"
    },
    {
      "createdAt": "2026-07-16T15:55:54.254140+00:00",
      "updatedAt": "2026-07-16T15:55:54.254143+00:00",
      "id": "3506c721492cc987",
      "name": "Agentic AI"
    },
    {
      "createdAt": "2026-07-16T15:55:54.254148+00:00",
      "updatedAt": "2026-07-16T15:55:54.254151+00:00",
      "id": "dac03ba206f3bfe0",
      "name": "Event-Driven Architecture"
    },
    {
      "createdAt": "2026-07-16T15:55:54.254156+00:00",
      "updatedAt": "2026-07-16T15:55:54.254159+00:00",
      "id": "87703e16953f8b2e",
      "name": "Data Pipeline"
    },
    {
      "createdAt": "2026-07-16T15:55:54.254164+00:00",
      "updatedAt": "2026-07-16T15:55:54.254166+00:00",
      "id": "89f5bd6077773f30",
      "name": "Production Automation"
    },
    {
      "createdAt": "2026-07-16T15:58:23.793245+00:00",
      "updatedAt": "2026-07-16T15:58:23.793258+00:00",
      "id": "332aea2c3b181c28",
      "name": "Event-Driven"
    }
  ]
}