Overview
The UniCraft Chat Model node provides a universal interface to interact with AI chat completion models via the UniCraft API. It supports both manual model selection and an automatic "Smart Routing" mode that chooses the best model based on predefined strategies and priorities. The node can accept input messages either directly from its parameters or from incoming data, making it flexible for various workflows.
Common scenarios where this node is beneficial include:
- Integrating advanced AI chat completions into automation workflows.
- Dynamically selecting the optimal AI model based on cost, performance, or availability without manual intervention.
- Using custom tools/functions alongside the AI model to extend capabilities.
- Processing multiple messages in batch with error handling per item.
Practical examples:
- A customer support workflow that routes user queries to different AI models depending on load or cost considerations.
- Content generation pipelines where the message prompt is dynamically passed from previous nodes.
- Experimenting with different AI models by switching between manual and smart routing modes.
Properties
| Name | Meaning |
|---|---|
| Input Source | Choose how to provide the message to the AI model: • Direct Input — enter the message directly in the node parameters. • From Input Data — use message(s) from connected input data. |
| Mode | Choose how to select the AI model: • Manual — manually select a specific model. • Smart Routing — automatically select the best model based on strategy and priority. |
| Model | (Shown if Mode = Manual) Select the specific AI model to use. Models are loaded dynamically from the UniCraft API. |
| Smart Routing Strategy | (Shown if Mode = Smart Routing) Select the strategy for automatic model selection. Options include Balanced, Cost Optimized, Performance Optimized, Availability Optimized, and Custom. |
| Priority | (Shown if Mode = Smart Routing) Set the priority level for model selection: Low, Normal, or High. |
| Message | (Shown if Input Source = Direct Input) The message text to send to the chat model. Required when using direct input. |
| System Prompt | (Shown if Input Source = Direct Input) Optional system message to set the behavior of the assistant. |
| Temperature | Sampling randomness parameter controlling creativity of responses. Range 0 to 2, default 0.7. |
| Additional Fields | Collection of optional parameters: • Max Tokens — maximum tokens to generate. • Top P — nucleus sampling parameter. • Frequency Penalty — penalize frequent tokens. • Presence Penalty — penalize new tokens. • Stream — enable streaming response. • Stop Sequences — comma-separated stop sequences to end generation. |
| Tools | Define custom tools/functions available to the AI model. Each tool requires a name, description, and JSON schema for parameters. |
Output
The node outputs an array of items corresponding to each input item processed. Each output item contains a json object with the following structure:
{
"response": {
"role": "assistant",
"content": "string", // The AI-generated reply text
"tool_calls": [] // Array of any tool/function calls made by the AI during response
},
"usage": {}, // Token usage statistics returned by the API
"model": "string", // The model used to generate the response
"provider": "unicraft", // Fixed provider identifier
"text": "string", // Same as content, convenience field
"message": "string", // Same as content, convenience field
"smartRouting": { // Present only if Smart Routing mode was used
"strategy": "string", // The selected smart routing strategy
"priority": "string", // The priority level used
"selectedModel": "string" // The actual model chosen by smart routing
}
}
If the node encounters errors and "Continue On Fail" is enabled, the output item will contain an error field describing the failure.
The node does not output binary data.
Dependencies
- Requires an API key credential for the UniCraft API, including a base URL and API key.
- The node makes HTTP requests to the UniCraft API endpoints
/api-key/models,/api/v1/smart-routing/strategies,/api-key/chat/completions, and/api-key/smart-chat/completions. - Proper configuration of the UniCraft API credentials in n8n is necessary.
- Internet access to the UniCraft API service.
Troubleshooting
- Missing Credentials: If the base URL or API key is missing or invalid, the node will throw an error indicating that credentials are required.
- Invalid Input Data: When using "From Input Data" as input source, the node expects the input JSON to contain either a
messagesarray or one of the fieldsmessage,text, orprompt. Absence of these will cause an error. - Empty Message: When using "Direct Input", the message field must not be empty; otherwise, an error is thrown.
- API Request Failures: Network issues, invalid API keys, or rate limits may cause request failures. The node surfaces these errors with descriptive messages.
- Model Loading Errors: Failure to load available models or smart routing strategies from the API will result in fallback options or errors.
- To resolve errors, verify credentials, ensure input data format correctness, and check network connectivity.
Links and References
- UniCraft API Documentation
- n8n Documentation on Creating Custom Nodes
- General info on OpenAI GPT Models (for context on model names like gpt-3.5-turbo)