openai-api

jezweb/claude-skills · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/jezweb/claude-skills --skill openai-api
0 commentsdiscussion
summary

Complete reference for OpenAI's stateless APIs including Chat Completions, embeddings, images, audio, and moderation.

  • Supports GPT-5 series (with reasoning_effort control), GPT-4o multimodal, o3 reasoning models, and legacy GPT-4 variants; streaming, function calling, and structured JSON outputs included
  • Embeddings API for RAG with custom dimensions (256–3072), DALL-E 3 image generation, Whisper transcription, and TTS with 11 voices
  • Batch API for 50% cost savings on large-scale proce
skill.md

OpenAI API - Complete Guide

Version: Production Ready ✅ Package: [email protected] Last Updated: 2026-01-20


Status

✅ Production Ready:

  • ✅ Chat Completions API (GPT-5, GPT-4o, GPT-4 Turbo)
  • ✅ Embeddings API (text-embedding-3-small, text-embedding-3-large)
  • ✅ Images API (DALL-E 3 generation + GPT-Image-1 editing)
  • ✅ Audio API (Whisper transcription + TTS with 11 voices)
  • ✅ Moderation API (11 safety categories)
  • ✅ Streaming patterns (SSE)
  • ✅ Function calling / Tools
  • ✅ Structured outputs (JSON schemas)
  • ✅ Vision (GPT-4o)
  • ✅ Both Node.js SDK and fetch approaches

Table of Contents

  1. Quick Start
  2. Chat Completions API
  3. GPT-5 Series Models
  4. Streaming Patterns
  5. Function Calling
  6. Structured Outputs
  7. Vision (GPT-4o)
  8. Embeddings API
  9. Images API
  10. Audio API
  11. Moderation API
  12. Error Handling
  13. Rate Limits
  14. Common Mistakes & Gotchas
  15. TypeScript Gotchas
  16. Production Best Practices
  17. Relationship to openai-responses

Quick Start

Installation

npm install [email protected]

Environment Setup

export OPENAI_API_KEY="sk-..."

Or create .env file:

OPENAI_API_KEY=sk-...

First Chat Completion (Node.js SDK)

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const completion = await openai.chat.completions.create({
  model: 'gpt-5',
  messages: [
    { role: 'user', content: 'What are the three laws of robotics?' }
  ],
});

console.log(completion.choices[0].message.content);

First Chat Completion (Fetch - Cloudflare Workers)

const response = await fetch('https://api.openai.com/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${env.OPENAI_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'gpt-5',
    messages: [
      { role: 'user', content: 'What are the three laws of robotics?' }
    ],
  }),
});

const data = await response.json();
console.log(data.choices[0].message.content);

Chat Completions API

Endpoint: POST /v1/chat/completions

The Chat Completions API is the core interface for interacting with OpenAI's language models. It supports conversational AI, text generation, function calling, structured outputs, and vision capabilities.

Supported Models

GPT-5 Series (Released August 2025)

  • gpt-5: Full-featured reasoning model with advanced capabilities
  • gpt-5-mini: Cost-effective alternative with good performance
  • gpt-5-nano: Smallest/fastest variant for simple tasks

GPT-4o Series

  • gpt-4o: Multimodal model with vision capabilities
  • gpt-4-turbo: Fast GPT-4 variant

GPT-4 Series (Legacy)

  • gpt-4: Original GPT-4 model (deprecated - use gpt-5 or gpt-4o)

Basic Request Structure

{
  model: string,              // Model to use (e.g., "gpt-5")
  messages: Message[],        // Conversation history
  reasoning_effort?: string,  // GPT-5 only: "minimal" | "low" | "medium" | "high"
  verbosity?: string,         // GPT-5 only: "low" | "medium" | "high"
  temperature?: number,       // NOT supported by GPT-5
  max_tokens?: number,        // Max tokens to generate
  stream?: boolean,           // Enable streaming
  tools?: Tool[],             // Function calling tools
}

Response Structure

{
  id: string,                 // Unique completion ID
  object: "chat.completion",
  created: number,            // Unix timestamp
  model: string,              // Model used
  choices: [{
    index: number,
    message: {
      role: "assistant",
      content: string,        // Generated text
      tool_calls?: ToolCall[] // If function calling
    },
    finish_reason: string     // "stop" | "length" | "tool_calls"
  }],
  usage: {
    prompt_tokens: number,
    completion_tokens: number,
    total_tokens: number
  }
}

Message Roles & Multi-turn Conversations

Three roles: system (behavior), user (input), assistant (model responses).

Important: API is stateless - send full conversation history each request. For stateful conversations, use openai-responses skill.


GPT-5 Series Models

GPT-5 models (released August 2025) introduce reasoning and verbosity controls.

GPT-5.2 (Released December 11, 2025)

Latest flagship model:

  • gpt-5.2: 400k context window, 128k output tokens
  • xhigh reasoning_effort: New level beyond "high" for complex problems
  • Compaction: Extends context for long workflows (via API endpoint)
  • Pricing: $1.75/$14 per million tokens (1.4x of GPT-5.1)
// GPT-5.2 with maximum reasoning
const completion = await openai.chat.completions.create({
  model: 'gpt-5.2',
  messages: [{ role: 'user', content: 'Solve this extremely complex problem...' }],
  reasoning_effort: 'xhigh', // NEW: Beyond "high"
});

GPT-5.1 (Released November 13, 2025)

Warmer, more intelligent model:

  • gpt-5.1: Adaptive reasoning that varies thinking time dynamically
  • 24-hour extended prompt caching: Faster follow-up queries at lower cost
  • New developer tools: apply_patch (code editing), shell (command execution)

BREAKING CHANGE: GPT-5.1/5.2 default to reasoning_effort: 'none' (vs GPT-5 defaulting to 'medium').

O-Series Reasoning Models

Dedicated reasoning models (separate from GPT-5):

Model Released Purpose
o3 Apr 16, 2025 Successor to o1, advanced reasoning
o3-pro Jun 10, 2025 Extended compute version of o3
o3-mini Jan 31, 2025 Smaller, faster o3 variant
o4-mini Apr 16, 2025 Fast, cost-efficient reasoning
// O-series models
const completion = await openai.chat.completions.create({
  model: 'o3',  // or 'o3-mini', 'o4-mini'
  messages: [{ role: 'user', content: 'Complex reasoning task...' }],
});

Note: O-series may be deprecated in favor of GPT-5 with reasoning_effort parameter.

reasoning_effort Parameter

Controls thinking depth (GPT-5/5.1/5.2):

  • "none": No reasoning (fastest) - GPT-5.1/5.2 default
  • "minimal": Quick responses (Note: May not be available - Issue #1690)
  • "low": Basic reasoning
  • "medium": Balanced - GPT-5 default
  • "high": Deep reasoning
  • "xhigh": Maximum reasoning (GPT-5.2 only)

verbosity Parameter

Controls output detail (GPT-5 series):

  • "low": Concise
  • "medium": Balanced (default)
  • "high": Verbose

GPT-5 Limitations

NOT Supported:

  • temperature, top_p, logprobs parameters
  • ❌ Stateful Chain of Thought between turns

Alternatives: Use GPT-4o for temperature/top_p, or openai-responses skill for stateful reasoning


Streaming Patterns

Enable with stream: true for token-by-token delivery.

Node.js SDK

how to use openai-api

How to use openai-api on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add openai-api
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

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

The skills CLI fetches openai-api from GitHub repository jezweb/claude-skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/openai-api

Reload or restart Cursor to activate openai-api. Access the skill through slash commands (e.g., /openai-api) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.550 reviews
  • Shikha Mishra· Dec 28, 2024

    Solid pick for teams standardizing on skills: openai-api is focused, and the summary matches what you get after install.

  • Advait Sharma· Dec 28, 2024

    openai-api fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Evelyn Rao· Dec 16, 2024

    Registry listing for openai-api matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Maya Perez· Dec 8, 2024

    We added openai-api from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Ganesh Mohane· Dec 4, 2024

    Useful defaults in openai-api — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Kofi Kapoor· Nov 27, 2024

    openai-api reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Sakshi Patil· Nov 23, 2024

    openai-api is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Zaid Shah· Nov 19, 2024

    Registry listing for openai-api matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Maya Ndlovu· Nov 7, 2024

    openai-api fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Isabella Martin· Oct 26, 2024

    We added openai-api from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

showing 1-10 of 50

1 / 5