Claude-skills 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.
install
source · Clone the upstream repo
git clone https://github.com/secondsky/claude-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/secondsky/claude-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/openai-api/skills/openai-api" ~/.claude/skills/secondsky-claude-skills-openai-api && rm -rf "$T"
manifest:
plugins/openai-api/skills/openai-api/SKILL.mdsource content
OpenAI API
Package: openai@6.9.1 | Last Updated: 2025-11-21
Quick Start
bun add openai export OPENAI_API_KEY="sk-..."
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
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
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
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
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)
const image = await client.images.generate({ model: 'gpt-image-1.5', prompt: 'A serene landscape', size: '1024x1024', quality: 'standard' // or 'hd' });
Audio
Transcription (Whisper):
const transcription = await client.audio.transcriptions.create({ file: fs.createReadStream('audio.mp3'), model: 'whisper-1' });
Text-to-Speech:
const speech = await client.audio.speech.create({ model: 'tts-1', voice: 'alloy', input: 'Hello world' });
Top Errors
- Invalid API Key (401): Verify OPENAI_API_KEY
- Rate Limit (429): Implement exponential backoff
- Model Not Found (404): Use correct model names
- Context Length (400): Reduce input size
- Invalid JSON: Fix function calling schemas
See:
references/error-catalog.md
Resources
Reference Guides
- Complete model comparison and selectionreferences/models-guide.md
- Function calling best practicesreferences/function-calling-patterns.md
- Structured outputs with JSON Schemareferences/structured-output-guide.md
- Text embeddings and vector searchreferences/embeddings-guide.md
- GPT-Image-1.5 image generationreferences/images-guide.md
- Whisper transcription + TTSreferences/audio-guide.md
- Token optimization and pricingreferences/cost-optimization.md
- Top 20 errors with solutionsreferences/top-errors.md
- Complete error referencereferences/error-catalog.md
Templates
- Quick start exampletemplates/basic-usage.ts
- Basic chat completiontemplates/chat-completion-basic.ts
- Node.js implementationtemplates/chat-completion-nodejs.ts
- Streaming responsestemplates/streaming-chat.ts
- Streaming with fetch APItemplates/streaming-fetch.ts
- Tools and function callingtemplates/function-calling.ts
- JSON Schema outputstemplates/structured-output.ts
- Vision with GPT-4otemplates/vision-gpt4o.ts
- Text embeddingstemplates/embeddings.ts
- GPT-Image-1.5 generationtemplates/image-generation.ts
- Image editingtemplates/image-editing.ts
- Whisper transcriptiontemplates/audio-transcription.ts
- TTS with voicestemplates/text-to-speech.ts
- Content moderationtemplates/moderation.ts
- Exponential backofftemplates/rate-limit-handling.ts
- Cloudflare Workers integrationtemplates/cloudflare-worker.ts