api-ai-openai-sdk
Official OpenAI SDK patterns for TypeScript/Node.js — client setup, Chat Completions, Responses API, streaming, structured outputs, function calling, embeddings, vision, audio, and production best practices
npx skills add majiayu000/claude-skill-registry --skill api-ai-openai-sdk --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Provides patterns to use the official OpenAI SDK (TypeScript/Node.js) for client setup, Chat Completions, the Responses API, streaming, structured outputs, function calling, embeddings, vision, audio, and batch processing.
How it works
- Recommends using the official npm package
openai(v6+) and choosing betweenclient.responses.create()(Responses API) andclient.chat.completions.create()(Chat Completions) depending on the project. - Enforces use of
zodResponseFormat()for structured outputs andclient.chat.completions.parse()to parse responses. - Uses
.stream()orstream: truefor streaming, and supports event-based or iterable consumption (for await...of). - Includes patterns for embedding, vision, audio, and batch processing via respective APIs.
- Emphasizes error handling with
OpenAI.APIErrorand configured retries/timeouts (default retries on 429/5xx). - Requires environment variable
OPENAI_API_KEYfor API keys. - Provides examples around client setup, chat completions, streaming, tool calling with
zodFunction, and structured outputs.
When to use it
- Building applications that call OpenAI models directly (GPT-5.x, GPT-4o, o4-mini, etc.).
- Implementing chat completions with streaming responses.
- Using the Responses API for agentic workflows with built-in tools (web/file search, code interpreter).
- Extracting structured data from LLM responses with Zod schema validation.
- Implementing function calling / tool use with Chat Completions or Responses API.
- Creating embeddings for RAG or semantic search.
- Processing images with vision models or audio with Whisper/TTS.
- Running batch jobs for high-volume, cost-efficient processing.
What it can touch
- Client:
client.responses.create()andclient.chat.completions.create()for main interactions. - Structured outputs via
zodResponseFormat()andclient.chat.completions.parse(). - Tools integration via
zodFunction()and optionalrunTools()for automated tool loops. - Embeddings:
client.embeddings.create(). - Vision/Audio:
client.audio.transcriptions.create()andclient.audio.speech.create(), plus image handling with image_url/base64. - Batch API via
client.batches.create(). - Error handling with
OpenAI.APIErrorand subclasses; environment-based configuration for retries/timeouts.
Caveats
- LICENSE: MIT. (Not a detail about usage but present in the skill metadata.)
- Requires adherence to project conventions (kebab-case, named exports, import ordering,
import type, named constants). - Not to be used for multi-provider switching; openAI-specific patterns only.
- Avoids hardcoding API keys; uses
process.env.OPENAI_API_KEY.
# OpenAI SDK Patterns > **Quick Guide:** Use the official `openai` npm package (v6+) to interact with OpenAI's API directly. Use `client.responses.create()` (Responses API) for new projects with built-in tools and server-side state, or `client.chat.completions.create()` (Chat Completions) for stateless chat flows. Use `zodResponseFormat` and `client.chat.completions.parse()` for structured outputs. Use `.stream()` or `stream: true` for streaming. Supports GPT-5.x family, GPT-4o, o4-mini, embeddings, vision, audio, and batch processing. --- <critical_requirements> ## CRITICAL: Before Using This Skill > **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants) **(You MUST use the Responses API (`client.responses.create()`) for new projects -- it provides better performance, built-in tools, and server-side conversation state)** **(You MUST use `zodResponseFormat()` from `openai/helpers/zod` for structured outputs -- do NOT manually construct JSON schemas)** **(You MUST handle errors using `OpenAI.APIError` and its subclasses -- never use bare catch blocks without error type checking)** **(You MUST configure a
- CRITICAL: Before Using This Skill
- Examples Index
- Philosophy
- Core Patterns
- Pattern 1: Client Setup
- Pattern 2: Chat Completions API
- Pattern 3: Responses API (Recommended for New Projects)
- Pattern 4: Streaming
- Pattern 5: Structured Outputs with Zod
- Pattern 6: Function Calling / Tool Use
- Pattern 7: Embeddings, Vision & Audio
- Pattern 8: Error Handling
- Performance Optimization
- Model Selection for Cost/Speed
What does the api-ai-openai-sdk skill do?
Official OpenAI SDK patterns for TypeScript/Node.js — client setup, Chat Completions, Responses API, streaming, structured outputs, function calling, embeddings, vision, audio, and production best practices
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-ai-openai-sdk --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
