n8n-nodes-openai-compatible-chat-trigger
v1.0.6
Published
OpenAI-compatible chat trigger and helper nodes for n8n.
Maintainers
Keywords
Readme
OpenAI-Compatible Chat Trigger & Tools for n8n
A custom n8n community node package that lets you expose your n8n workflows as direct, OpenAI-compatible chatbot backends. Instead of exposing standard Webhook URLs and mapping custom endpoints, this plugin exposes standard OpenAI API endpoints (/v1/chat/completions, /v1/completions, /v1/models) natively, allowing you to connect n8n workflows directly to any external chatbot program or library that supports OpenAI-compatible APIs (such as LibreChat, Chatbox, etc.).
Key Features
OpenAI-Compatible Chat Trigger Node:
- Registers a wildcard path that catches POST requests for
/v1/chat/completionsand/v1/completions. - Directly answers GET requests for
/v1/modelswithout executing the workflow, returning a custom mock models list. - Built-in authorization support (Bearer API keys) that immediately responds with a
401 Unauthorizedblock to clients on validation failure. - Extracts prompt messages, historical chat messages, and the requested model name into easy-to-use variables (
message,messages,model) for downstream nodes.
- Registers a wildcard path that catches POST requests for
OpenAI Completions Response Node:
- Automatically packages generated text from your workflow into the standard OpenAI Chat Completion or Text Completion JSON schemas.
- Exposes parameters to customize response model name, role, finish reason, and optional custom ID or created timestamp.
- Feeds back cleanly to the Chat Trigger node when set to "When Last Node Finishes".
Installation
For Local Development & Testing
- Clone or download this repository.
- In the folder, compile the TypeScript code and copy assets:
npm run build - Navigate to your local n8n data directory (typically
~/.n8n/on Linux/macOS orC:\Users\<Username>\.n8n\on Windows). - Create the nested directories if they do not exist:
mkdir -p ~/.n8n/custom/node_modules/ - Copy or symlink your package directory (
n8n-nodes-openai-compatible-chat-trigger) into that folder:# On Linux/macOS ln -s /path/to/n8n-nodes-openai-compatible-chat-trigger ~/.n8n/custom/node_modules/n8n-nodes-openai-compatible-chat-trigger - Restart your n8n server. The new nodes will be discoverable in the node selector.
Node Configurations
1. OpenAI-Compatible Chat Trigger
- Webhook Path Prefix (
path): The custom namespace prefix. For example, setting this tomy-botcreates these active endpoints:POST /webhook/my-bot/v1/chat/completions(starts workflow)POST /webhook/my-bot/v1/completions(starts workflow)GET /webhook/my-bot/v1/models(immediate GET response list)
- Response Mode (
responseMode): Set toWhen Last Node Finishes(returns output of the final node) orUsing Respond to Webhook Node. - Authentication (
authentication):NoneorHeader (Bearer Token). If set to header authentication, provide anAPI Key. - Mock Models (
mockModels): Comma-separated list of models returned from the/v1/modelsendpoint (e.g.gpt-3.5-turbo, gpt-4o, my-n8n-agent). - Support File Uploads / Vision (
supportFiles): Enable/disable parsing of base64 image/file payloads from the client message. Parses them into native n8n binary files. - Allowed File Types (
allowedFileTypes): Comma-separated list of allowed MIME types (e.g.,image/png, image/jpeg, image/webp). Non-matching files are skipped. - Support Tools / Function Calling (
supportTools): Enable/disable tools. If disabled, incoming tool calling definitions are filtered out to prevent errors in downstream nodes.
2. OpenAI Completions Response
- Response Type (
responseType): ChooseChat CompletionsorText Completions. - Response Text (
text): The final text content to return to the caller (e.g.{{ $json.text }}). - Model Name (
model): The model name value injected into the JSON metadata (e.g.gpt-3.5-turbo). - Message Role (
role): Message role (e.g.,assistant). - Finish Reason (
finishReason): Standard OpenAI stop reasons (e.g.,stop,length,content_filter). - Additional Fields: Optional custom ID and Unix epoch created timestamp overrides.
API Testing Examples
Ensure you use your Test URL when testing inside the n8n editor, and the Production URL when the workflow is published and activated.
1. Get Models List
curl -X GET "http://localhost:5678/webhook/openai-compatible/v1/models" \
-H "Authorization: Bearer <your-api-key>"2. Send Chat Completions Request
curl -X POST "http://localhost:5678/webhook/openai-compatible/v1/chat/completions" \
-H "Authorization: Bearer <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Hello chatbot, how are you?"}
]
}'License
This community node package is licensed under the MIT License.
