{"product_id":"self-hosted-chat-widget-for-n8n-w-openai-compatible-llm","title":"Self-Hosted Chat Widget for n8n w\/ OpenAI-Compatible LLM","description":"\u003ch3\u003eEmbed a self-hosted AI chat widget on your website—powered by an OpenAI-compatible LLM through n8n\u003c\/h3\u003e\n\u003cp\u003eThis n8n automation provides an embeddable website chat widget that sends visitor messages to an OpenAI-compatible \u003cstrong\u003e\/chat\/completions\u003c\/strong\u003e endpoint, keeps lightweight per-session conversation context, and returns the assistant’s reply to the browser—fully self-hosted.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eServes a ready-to-embed chat script:\u003c\/strong\u003e On \u003ccode\u003eGET \/webhook\/chat-widget.js\u003c\/code\u003e, the workflow returns a JavaScript snippet that renders a chat bubble and posts user messages to your n8n endpoint.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAccepts chat messages from visitors:\u003c\/strong\u003e On \u003ccode\u003ePOST \/webhook\/chat-message\u003c\/code\u003e, it receives a payload containing \u003ccode\u003esessionId\u003c\/code\u003e and \u003ccode\u003emessage\u003c\/code\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eMaintains session history:\u003c\/strong\u003e It loads and updates conversation history using n8n workflow static data, keeping only the most recent messages.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCalls your OpenAI-compatible LLM:\u003c\/strong\u003e It sends the configured system prompt plus the session history to an OpenAI-compatible \u003ccode\u003e\/chat\/completions\u003c\/code\u003e API using environment variables for base URL, model, and API key.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReturns a JSON reply to the widget:\u003c\/strong\u003e It extracts the assistant response, appends it to history, and returns \u003ccode\u003e{ \"reply\": \"...\" }\u003c\/code\u003e to the front-end.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eAdd a branded AI support chat to your site without using third-party widget platforms.\u003c\/li\u003e\n  \u003cli\u003eEnable SaaS onboarding Q\u0026amp;A with persistent per-session context handled by n8n.\u003c\/li\u003e\n  \u003cli\u003eLet automation engineers test OpenAI-compatible providers by swapping \u003ccode\u003eCHAT_LLM_API_BASE\u003c\/code\u003e and \u003ccode\u003eCHAT_LLM_MODEL\u003c\/code\u003e.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eWebhook endpoints:\u003c\/strong\u003e \u003ccode\u003e\/webhook\/chat-widget.js\u003c\/code\u003e and \u003ccode\u003e\/webhook\/chat-message\u003c\/code\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eNodes used:\u003c\/strong\u003e \u003cem\u003ecode\u003c\/em\u003e, \u003cem\u003ewebhook\u003c\/em\u003e, \u003cem\u003ehttp request\u003c\/em\u003e, \u003cem\u003erespond to webhook\u003c\/em\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eEnvironment variables:\u003c\/strong\u003e \u003ccode\u003eCHAT_LLM_API_KEY\u003c\/code\u003e (required), plus optional \u003ccode\u003eCHAT_LLM_API_BASE\u003c\/code\u003e, \u003ccode\u003eCHAT_LLM_MODEL\u003c\/code\u003e, and \u003ccode\u003eCHAT_LLM_SYSTEM_PROMPT\u003c\/code\u003e.\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003eActivate the workflow, copy both webhook URLs, and embed the script tags on your website by setting \u003ccode\u003ewindow.N8N_CHAT_WIDGET_CONFIG.endpoint\u003c\/code\u003e to your POST webhook URL (optionally configure title and accent color).\u003c\/p\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45978913964211,"sku":"N8N-19361","price":16.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/mPIVaemIa6LjSb5WfKJA5_A8a5PAY3.png?v=1788858578","url":"https:\/\/buyflowscripts.com\/products\/self-hosted-chat-widget-for-n8n-w-openai-compatible-llm","provider":"N8N Commerce","version":"1.0","type":"link"}