Skip to content

openai-api

Use when integrating OpenAI models via the openai Node.js SDK — Chat Completions, tool use/function calling, structured outputs, vision, image generation (gpt-image-1), embeddings, streaming, or the Responses API. Also use when choosing between OpenAI models or migrating from the Assistants API.

ModelSource
sonnetpack: ai
Full Reference

┏━ 🔧 openai-api ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Use when integrating OpenAI models via the ope… ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Direct OpenAI API access via the openai SDK. Chat Completions is the primary interface; the Responses API is the modern replacement for Assistants.

ItemValue
Installnpm install openai
SDK versionv4.x
Node.js minimum18+
Env varOPENAI_API_KEY
Default modelgpt-4o-mini (best value)
Code modelgpt-4.1
Reasoning modelo4-mini
Embeddings modeltext-embedding-3-small
Image generationgpt-image-1 (DALL-E 3 deprecated May 2026)
Assistants API sunsetAugust 26, 2026 — use Responses API
I want to…File
Install the SDK and initialize the clientreference/setup.md
Choose the right model for my use casereference/models.md
Send messages, stream responses, or build multi-turn chatsreference/chat-completions.md
Define tools and handle function callsreference/tool-use.md
Guarantee JSON schema-conformant outputsreference/structured-outputs.md
Send images or analyze visual contentreference/vision.md
Generate or edit imagesreference/image-generation.md
Create vector embeddings for RAG or semantic searchreference/embeddings.md
Use the Responses API (Assistants replacement)reference/responses-api.md
Handle errors, retry on rate limits, understand finish_reasonreference/error-handling.md

Usage: Read the reference file matching your current task from the index above. Each file is self-contained with code examples and inline gotchas.

  • vercel-ai-sdk — Multi-provider abstraction (wraps OpenAI + Anthropic + Gemini)
  • anthropic-api — Claude alternative
  • google-genai — Gemini alternative
  • postgresql-pgvector — Store and query OpenAI embeddings in Postgres