mcpField
O
openai-api

openai-api

github.com/secondskyDevelopment247136 installsUpdated 6w ago
Repository

About openai-api

openai-api is a skill for developers integrating the OpenAI API through its SDK or HTTP requests. Its guides and templates cover chat, streaming, function calling, embeddings, image generation, and audio tasks.

Key features

  1. 01Chat completions and streaming
  2. 02Function calling and structured output
  3. 03Text embeddings
  4. 04Image generation and editing
  5. 05Audio transcription and speech

Use cases

  1. 01Adding streamed chat to an application
  2. 02Connecting model responses to functions
  3. 03Generating embeddings for text
  4. 04Transcribing audio or creating speech

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/secondsky/claude-skills --skill openai-api

After installing, type/openai-apiin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
audio-guide.md
cost-optimization.md
embeddings-guide.md
error-catalog.md
function-calling-patterns.md
images-guide.md
models-guide.md
structured-output-guide.md
top-errors.md
scripts/
check-versions.sh
templates/
audio-transcription.ts
basic-usage.ts
chat-completion-basic.ts
chat-completion-nodejs.ts
cloudflare-worker.ts
embeddings.ts
function-calling.ts
image-editing.ts
image-generation.ts
moderation.ts
package.json
rate-limit-handling.ts
streaming-chat.ts
streaming-fetch.ts
structured-output.ts
text-to-speech.ts
vision-gpt4o.ts

Details

From the project README

OpenAI API

Package: [email protected] | 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

  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

Comments

Markdown supported