Overview
This node provides an interface to interact with a wide range of AI/ML chat completion models via an external API. It allows users to send prompts to selected AI models and receive generated text completions or structured responses. This is useful for automating content generation, conversational agents, summarization, or any task requiring natural language understanding and generation.
Typical use cases include:
- Generating chatbot replies based on user input.
- Creating content such as articles, emails, or code snippets.
- Summarizing or expanding text dynamically.
- Experimenting with different AI models to find the best fit for specific tasks.
Properties
| Name | Meaning |
|---|---|
| Model Name or ID | Select an AI model from a dynamically loaded list or specify a model ID using an expression. Models are filtered to those supporting chat completions. |
| Prompt | The text prompt sent to the AI model to generate a response. |
| Extract From Response | Choose which part of the AI response to return: - Text Only (First Message): Returns the first message's text content. - Assistant Messages: Returns all assistant messages. - Choices Array: Returns the full choices array. - Full Raw JSON: Returns the entire raw JSON response. |
| Options | Additional parameters to customize the AI completion request: - Frequency Penalty: Penalizes repeated tokens (-2 to 2). - Max Tokens: Maximum tokens to generate. - Presence Penalty: Penalizes new topics (-2 to 2). - Response Format: Default (full JSON) or Text Only. - Temperature: Sampling temperature controlling randomness (0-2). - Top P: Nucleus sampling parameter (0-1). |
Output
The output is a JSON array containing one object per input item, with the structure depending on the "Extract From Response" property:
- Text Only (First Message):
{ "content": "<text>" }— the textual content of the first message returned by the AI. - Assistant Messages:
{ "result": [<array of message objects>] }— all assistant messages from the choices. - Choices Array:
{ "result": [<array of choice objects>] }— the full array of choices returned by the AI. - Full Raw JSON:
{ "result": <full raw JSON response> }— the complete JSON response from the API.
No binary data output is produced by this node.
Dependencies
- Requires an API key credential for authentication with the external AI/ML API service.
- The base URL for the API is configured in the credentials.
- The node dynamically loads available AI models from the API endpoint
/models. - No additional environment variables are required beyond the API credential configuration.
Troubleshooting
Common Issues:
- Invalid or missing API credentials will cause authentication failures.
- Specifying a model ID that does not support chat completions may result in errors or empty responses.
- Incorrect prompt formatting or unsupported options might lead to unexpected results or API errors.
Error Messages:
- Authentication errors typically indicate invalid or expired API keys; verify and update credentials.
- HTTP errors from the API (e.g., 400 Bad Request) often mean invalid parameters; check the prompt and options.
- If no models load in the dropdown, ensure the API URL is correct and reachable.
Resolution Tips:
- Confirm API credentials and permissions.
- Use the "Model Name or ID" dropdown to select valid models.
- Adjust options like temperature and max tokens within allowed ranges.
- Review API documentation for supported parameters and limits.
Links and References
- n8n Expressions Documentation
- Refer to your AI/ML API provider’s official documentation for detailed model capabilities and parameter descriptions.