Overview
The openai node provides access to OpenAI's GPT models for text generation,
analysis, and chat completions. Transform IoT data into insights, generate reports, and enable natural language
interfaces for your edge devices.
GPT-4
Latest Model
128K
Context Window
Vision
Image Analysis
Stream
Real-time
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| apiKey | string | env | OpenAI API key |
| model | string | "gpt-4o" | Model to use (gpt-4o, gpt-4-turbo, gpt-3.5-turbo) |
| systemPrompt | string | "" | System message to set context |
| temperature | number | 0.7 | Creativity (0-2, lower = more deterministic) |
| maxTokens | number | 1000 | Maximum response length |
| stream | boolean | false | Stream response tokens |
Inputs & Outputs
Input
// Simple prompt
{
"payload": "Analyze this sensor data..."
}
// With conversation history
{
"payload": "Follow up question",
"messages": [
{ "role": "user", "content": "Previous..." },
{ "role": "assistant", "content": "Response..." }
]
} Output
{
"payload": "AI generated response...",
"usage": {
"prompt_tokens": 150,
"completion_tokens": 200,
"total_tokens": 350
},
"model": "gpt-4o"
} Available Models
GPT-4o
Most capable, multimodal (text + vision)
128K context Vision
GPT-4 Turbo
Fast, capable, good for complex tasks
128K context JSON mode
GPT-3.5 Turbo
Fast and cost-effective for simpler tasks
16K context Low cost
GPT-4o Mini
Balanced performance and cost
128K context Best value
Example: Sensor Data Analysis
Use AI to analyze sensor patterns and generate insights.
// Function node: Prepare analysis request
var readings = msg.payload; // Array of sensor readings
msg.payload = `Analyze this IoT sensor data and identify any anomalies or patterns:
${JSON.stringify(readings, null, 2)}
Provide:
1. Summary of the data
2. Any anomalies detected
3. Recommended actions`;
msg.systemPrompt = `You are an IoT data analyst. Analyze sensor data and provide
actionable insights. Be concise and focus on anomalies that need attention.`;
msg.temperature = 0.3; // Lower for more consistent analysis
return msg; Example: Image Analysis with Vision
Analyze camera images using GPT-4 Vision.
// Function node: Analyze camera snapshot
var imageBuffer = msg.payload;
var base64Image = imageBuffer.toString('base64');
msg.payload = {
messages: [{
role: "user",
content: [
{
type: "text",
text: "Describe what you see in this security camera image. Focus on any people, vehicles, or unusual activity."
},
{
type: "image_url",
image_url: {
url: "data:image/jpeg;base64," + base64Image
}
}
]
}]
};
msg.model = "gpt-4o";
return msg;