Custom Chat Model icon

Custom Chat Model

Chat com modelo de IA personalizado

Overview

This node implements a custom chat completion model integration for n8n. It allows users to generate AI-powered chat responses based on a sequence of input messages and configurable parameters. The node is useful in scenarios where you want to simulate or integrate a personalized AI chat model that responds contextually to user inputs, system instructions, and assistant messages.

Practical examples include:

  • Building conversational agents or chatbots with customized behavior.
  • Generating automated replies in customer support workflows.
  • Creating interactive assistants that follow specific system prompts or guidelines.

The node simulates the response generation by returning a mock answer referencing the selected model and input messages, which can be replaced with real API calls in a production environment.

Properties

Name Meaning
Model The name of the custom AI model to use for generating chat completions.
Messages A collection of chat messages forming the conversation history. Each message has:
- Role: The role of the message sender (System, User, Assistant).
- Content: The textual content of the message.
System Prompt Optional system-level instructions to guide the AI model's behavior in the chat.
Options Collection of parameters controlling the generation:
- Temperature Controls randomness of responses (0 = deterministic, 1 = very random).
- Max Tokens Maximum number of tokens allowed in the generated response.
- Top P Nucleus sampling parameter controlling diversity (0-1).
- Presence Penalty Penalizes repeated topics (-2 to 2).
- Frequency Penalty Penalizes token repetition (-2 to 2).
- Timeout (ms) Maximum time to wait for the API response in milliseconds.
- Max Retries Number of retry attempts if the request fails.

Output

The node outputs an array of JSON objects, each containing:

  • response: The generated text response from the AI model.
  • text: Same as response, the textual content of the reply.
  • messageId: A unique identifier for the chat completion instance.
  • role: The role of the message sender, always "assistant" for the generated reply.
  • history: An array of all messages including the input conversation plus the generated assistant message.
  • metadata: Contains details about the model used, usage statistics (tokens), and generation options applied.

No binary data output is produced by this node.

Dependencies

  • Requires an API key credential and a URL endpoint for the custom chat model service.
  • The node expects these credentials to be configured in n8n under a generic API key authentication.
  • No external libraries beyond standard Node.js are required.
  • Network access to the specified API endpoint is necessary.

Troubleshooting

  • Common issues:

    • Missing or invalid API key credential will cause authentication failures.
    • Incorrect or unreachable API URL will result in network errors or timeouts.
    • Exceeding max tokens or timeout limits may cause incomplete or failed responses.
  • Error messages:

    • Errors thrown during execution will either stop the workflow or be returned as error JSON if "Continue On Fail" is enabled.
    • Typical errors relate to credential misconfiguration, network connectivity, or invalid parameter values.
  • Resolutions:

    • Verify API key and endpoint URL correctness.
    • Adjust timeout and retry settings for unstable networks.
    • Ensure input messages and parameters conform to expected formats.

Links and References

Discussion