Grok icon

Grok

Interact with Grok API

Overview

This n8n node allows you to interact with the Grok API, specifically to send chat messages to a selected AI model and receive responses. It is designed for scenarios where you want to automate conversations or integrate AI-powered chat capabilities into your workflows. Common use cases include building virtual assistants, automating customer support replies, or generating text based on prompts within an n8n automation.

Practical examples:

  • Automatically generate answers to user questions using Grok's AI.
  • Use dynamic system prompts to guide the assistant's behavior in different workflow branches.
  • Integrate Grok's chat completions into multi-step automation processes.

Properties

Display Name Type Description
Model Name or ID options Choose from available models or specify an ID via expression. Required.
System Prompt string (Optional) System message to set the behavior of the assistant.
Message string The message to send to the chat model. Required.
Temperature number Sampling temperature for response randomness. Default is 0.9.
Additional Fields collection Optional advanced settings:
- Frequency Penalty (number): Penalize new tokens by frequency.
- Max Tokens (number): Maximum tokens to generate.
- Presence Penalty (number): Penalize new tokens by presence.
- Top P (number): Nucleus sampling parameter.

Output

The node outputs a JSON object for each input item:

{
  "response": "<AI-generated response string>"
}
  • If an error occurs and "Continue On Fail" is enabled, the output will be:
{
  "error": "<Error message>"
}

Dependencies

  • External Service: Requires access to the Grok API (https://api.x.ai/v1/).
  • API Key: You must provide a valid Grok API key via n8n credentials named grokApi.
  • n8n Configuration: No additional configuration required beyond setting up the credential.

Troubleshooting

Common Issues:

  • Missing API Key: If no valid API key is provided, the node will throw an error:
    "No valid API key provided"
  • Invalid Model Selection: If the model list cannot be loaded or is empty, errors like "No models found in Grok API response" or "Failed to load models: ..." may occur.
  • Malformed API Response: If the Grok API returns an unexpected format, you may see:
    "Invalid response format from Grok API"
  • Network/API Errors: Any network issues or invalid requests will result in error messages from the Grok API.

How to resolve:

  • Ensure your API key is correct and active.
  • Verify that the Grok API service is reachable from your n8n instance.
  • Double-check all required fields, especially "Model Name or ID" and "Message".
  • For advanced parameters, ensure values are within expected ranges (e.g., penalties between -2.0 and 2.0).

Links and References

Discussion