OpenAI
Integrate OpenAI's GPT models, embeddings, and image generation into your Spala flows.
OpenAI
The OpenAI addon connects your Spala flows to OpenAI's API for chat completions, text embeddings, and image generation. Build AI-powered features like chatbots, content generation, semantic search, and automated analysis.
Installation
1. Enable the OpenAI addon from the Addons panel 2. Enter your OpenAI API key in the addon configuration
Configuration
Available Steps
Chat Completion
Generates a chat response from an OpenAI model.
// Example messages input:
[
{ role: 'system', content: 'You are a helpful customer support agent.' },
{ role: 'user', content: input.userMessage }
]
Create Embedding
Generates vector embeddings for text, useful for semantic search and similarity matching.
Generate Image
Creates images from text descriptions using an OpenAI image model.
Example: AI Chatbot Endpoint
// POST /api/chat
// Step 1: Database Query - Get conversation history // SELECT * FROM messages WHERE conversation_id = input.conversationId // ORDER BY created_at ASC LIMIT 20
// Step 2: Chat Completion (OpenAI addon)
// model: '<current-openai-model>'
// messages: [
// { role: 'system', content: 'You are a helpful assistant for our e-commerce store.' },
// ...vars.history.map(m => ({ role: m.role, content: m.content })),
// { role: 'user', content: input.message }
// ]
// Output → vars.aiResponse
// Step 3: Database Query - Save the messages // INSERT INTO messages (conversation_id, role, content) // VALUES (input.conversationId, 'user', input.message), // (input.conversationId, 'assistant', vars.aiResponse.choices[0].message.content)
// Step 4: Response
// { reply: vars.aiResponse.choices[0].message.content }
Example: Semantic Search
// POST /api/search
// Step 1: Create Embedding (OpenAI addon) // model: 'text-embedding-3-small' // input: input.query // Output → vars.embedding
// Step 2: Database Query - Find similar documents // SELECT *, (embedding <=> $1) AS distance // FROM documents ORDER BY distance LIMIT 10 // Params: [vars.embedding.data[0].embedding]
// Step 3: Response
// { results: vars.documents }
OpenAI API calls are billed per token. Monitor your usage in the OpenAI dashboard and set billing limits to avoid unexpected charges.
Your OpenAI API key from platform.openai.com/api-keys. The OpenAI model to use. Choose a currently supported model from OpenAI. Array of message objects with 'role' and 'content' fields. Sampling temperature between 0 and 2 (default: 1). Lower values are more deterministic. Maximum number of tokens to generate. The embedding model (e.g., 'text-embedding-3-small'). The text string to embed, or an array of strings for batch embedding. A text description of the image to generate. The OpenAI image model to use. Image size: '1024x1024', '1792x1024', or '1024x1792'. 'standard' or 'hd' (default: 'standard'). Addons Overview /addons Browse available addons Installing Addons /addons/installing Enable and configure addons in your project