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.
View on GitHubsecondsky/claude-skills
openai-api
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/secondsky/claude-skills/blob/main/plugins/openai-api/skills/openai-api/SKILL.md -a claude-code --skill openai-apiInstallation paths:
.claude/skills/openai-api/# OpenAI API
**Package**: openai@6.9.1 | **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)
```typescrip