Overview
This node provides AI chat completion functionality by interacting with an external AI/ML API service. It sends a user-defined prompt to a selected AI model and returns the generated response. This is useful for automating conversational tasks, generating text content, summarizing information, or building chatbots within n8n workflows.
Typical use cases include:
- Generating natural language responses based on prompts.
- Automating customer support replies.
- Creating content drafts or ideas.
- Extracting insights from textual data via AI models.
Properties
| Name | Meaning |
|---|---|
| Model Name or ID | Select an AI model from a dynamically loaded list or specify a model ID using an expression. The chosen model will be used to generate the chat completion. |
| Prompt | The text prompt sent to the AI model to generate a response. This is the main input that drives the AI's output. |
| Extract From Response | Choose which part of the AI response to return: - Text Only (First Message): Returns only the first message's text content. - Assistant Messages: Returns all assistant messages. - Choices Array: Returns the full array of choices. - Full Raw JSON: Returns the complete raw JSON response from the API. |
| Options | Additional parameters to customize the AI generation: - Frequency Penalty: Penalizes repeated tokens (-2 to 2). - Max Tokens: Maximum tokens to generate. - Presence Penalty: Penalizes new topics (-2 to 2). - Response Format: Output format, either full JSON or text only. - Temperature: Sampling temperature controlling randomness (0-2). - Top P: Nucleus sampling parameter (0-1). |
Output
The node outputs JSON data structured according to the "Extract From Response" property:
- Text Only (First Message): Outputs an array with one object containing the key
contentholding the first message's text string. - Assistant Messages: Outputs an array with one object containing the key
resultholding an array of all assistant messages. - Choices Array: Outputs an array with one object containing the key
resultholding the full array of choice objects returned by the AI. - Full Raw JSON: Outputs an array with one object containing the key
resultholding the entire raw JSON response from the API.
No binary data output is produced by this node.
Dependencies
- Requires connection to an external AI/ML API service endpoint.
- Needs an API key credential and base URL configured in n8n credentials for authentication.
- The node dynamically loads available AI models from the API before execution.
Troubleshooting
Common Issues:
- Invalid or missing API key or base URL can cause authentication failures.
- Selecting a model that does not support chat completions may result in errors or empty responses.
- Providing invalid parameter values (e.g., out-of-range penalties or token limits) might cause request rejections.
- Network connectivity issues to the API endpoint will prevent successful requests.
Error Messages & Resolutions:
- Authentication errors: Verify API key and base URL are correctly set in credentials.
- Model not found: Ensure the selected model supports chat completions and is available in the API.
- Invalid parameter value: Check that numeric options like temperature, penalties, and max tokens are within allowed ranges.
- Empty or malformed response: Confirm the prompt is valid and the API service is operational.
Links and References
- n8n Expressions Documentation
- Refer to your AI/ML API provider’s official documentation for detailed model capabilities and parameter descriptions.