OpenAI Integration
Add GPT-4 chat, DALL-E image generation, Whisper transcription, and embeddings to your app.
🤖 OpenAI Capabilities
💬 GPT-4 / GPT-4o
Chat completions, reasoning, code generation, analysis
🎨 DALL-E 3
Generate images from text descriptions
🎙️ Whisper
Speech-to-text transcription in 50+ languages
🔍 Embeddings
Semantic search, similarity matching, RAG
🛠️ Setup
- 1Get your API key
Create an account at platform.openai.com and get your API key.
- 2Add environment variableOPENAI_API_KEY=sk-...
💬 Chat Completion
Build a ChatGPT-style interface with streaming responses:
import OpenAI from 'openai'
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
})
// Chat completion with streaming
const stream = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: userMessage }
],
stream: true,
})
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || ''
// Stream content to UI
}🎨 Image Generation (DALL-E)
const image = await openai.images.generate({
model: 'dall-e-3',
prompt: 'A serene mountain landscape at sunset',
size: '1024x1024',
quality: 'hd',
})
const imageUrl = image.data[0].url💬 Example Prompts for Spawned
Chat & Assistants
- "Add an AI chatbot using GPT-4 with streaming responses and conversation history."
- "Create an AI writing assistant that helps improve text. Include tone and style options."
- "Build a code review assistant that analyzes pasted code and suggests improvements."
Image Generation
- "Add AI image generation with DALL-E. Let users enter a prompt and see the result."
- "Create a logo generator that creates logos from business descriptions using DALL-E."
Voice & Transcription
- "Add voice recording with automatic transcription using Whisper."
- "Create meeting notes that transcribe audio files and summarize key points."
💰 Pricing Note
OpenAI charges per API call. GPT-4o is ~$2.50/1M input tokens. DALL-E 3 is ~$0.04/image. Set up usage limits in your OpenAI dashboard to control costs.