openai-api
Complete guide for OpenAI APIs: Chat Completions (GPT-5.2, GPT-4o), Embeddings, Images (GPT-Image-1.5), Audio (Whisper + TTS + Transcribe), Moderation. Includes Node.js SDK and fetch approaches.
What this skill does
# OpenAI API **Package**: [email protected] | **Last Updated**: 2025-11-21 ## Quick Start ```bash bun add openai export OPENAI_API_KEY="sk-..." ``` ```typescript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'Hello!' }] }); ``` ## Current Models (2025) - **gpt-5.2**: Most capable (128k context) - **gpt-4o**: Fast multimodal (128k context) - **gpt-4o-mini**: Cost-effective (128k context) - **gpt-4o-transcribe**: Audio transcription optimized - **gpt-4o-mini-transcribe**: Cost-effective transcription - **o1-preview**: Advanced reasoning (128k context) - **o1-mini**: Fast reasoning (128k context) ## Chat Completions ```typescript const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [ { role: 'system', content: 'You are a helpful assistant' }, { role: 'user', content: 'Explain AI' } ], temperature: 0.7, max_tokens: 1000 }); ``` ## Streaming ```typescript const stream = await client.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'Tell a story' }], stream: true }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || ''); } ``` ## Function Calling ```typescript const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'What is the weather?' }], tools: [{ type: 'function', function: { name: 'getWeather', parameters: { type: 'object', properties: { location: { type: 'string' } }, required: ['location'] } } }] }); ``` ## Embeddings ```typescript const response = await client.embeddings.create({ model: 'text-embedding-3-small', input: 'Your text here' }); const embedding = response.data[0].embedding; // 1536 dimensions ``` ## Images (GPT-Image-1.5) ```typescript const image = await client.images.generate({ model: 'gpt-image-1.5', prompt: 'A serene landscape', size: '1024x1024', quality: 'standard' // or 'hd' }); ``` ## Audio **Transcription (Whisper)**: ```typescript const transcription = await client.audio.transcriptions.create({ file: fs.createReadStream('audio.mp3'), model: 'whisper-1' }); ``` **Text-to-Speech**: ```typescript const speech = await client.audio.speech.create({ model: 'tts-1', voice: 'alloy', input: 'Hello world' }); ``` ## Top Errors 1. **Invalid API Key (401)**: Verify OPENAI_API_KEY 2. **Rate Limit (429)**: Implement exponential backoff 3. **Model Not Found (404)**: Use correct model names 4. **Context Length (400)**: Reduce input size 5. **Invalid JSON**: Fix function calling schemas **See**: `references/error-catalog.md` ## Resources ### Reference Guides - `references/models-guide.md` - Complete model comparison and selection - `references/function-calling-patterns.md` - Function calling best practices - `references/structured-output-guide.md` - Structured outputs with JSON Schema - `references/embeddings-guide.md` - Text embeddings and vector search - `references/images-guide.md` - GPT-Image-1.5 image generation - `references/audio-guide.md` - Whisper transcription + TTS - `references/cost-optimization.md` - Token optimization and pricing - `references/top-errors.md` - Top 20 errors with solutions - `references/error-catalog.md` - Complete error reference ### Templates - `templates/basic-usage.ts` - Quick start example - `templates/chat-completion-basic.ts` - Basic chat completion - `templates/chat-completion-nodejs.ts` - Node.js implementation - `templates/streaming-chat.ts` - Streaming responses - `templates/streaming-fetch.ts` - Streaming with fetch API - `templates/function-calling.ts` - Tools and function calling - `templates/structured-output.ts` - JSON Schema outputs - `templates/vision-gpt4o.ts` - Vision with GPT-4o - `templates/embeddings.ts` - Text embeddings - `templates/image-generation.ts` - GPT-Image-1.5 generation - `templates/image-editing.ts` - Image editing - `templates/audio-transcription.ts` - Whisper transcription - `templates/text-to-speech.ts` - TTS with voices - `templates/moderation.ts` - Content moderation - `templates/rate-limit-handling.ts` - Exponential backoff - `templates/cloudflare-worker.ts` - Cloudflare Workers integration **Docs**: https://platform.openai.com/docs
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.