@apicity/openai
OpenAI / GPT provider for chat completions.
Realtime voice over WebRTC: openai.post.v1.realtime.calls({ sdp, session }) sends the browser's SDP offer and resolves to the SDP answer plus the callId (from the Location header). The @apicity/openai/realtime subpath exports connectOpenAiRealtime, which opens a server-side WebSocket to that call (callId) or to a new session (model): send() client events such as session.update, and receive server events through onEvent. openai.post.v1.realtime.calls.hangup(callId) ends the call.
Runtime dependencies:
ws@^8.21.0— WebSocket client for the Realtime server control channel in@apicity/openai/realtimezod@^4.6.6— request schemas attached to every POST endpoint as.schema
Installation
npm install @apicity/openai
# or
pnpm add @apicity/openai
Quick Start
import { createOpenAi } from "@apicity/openai";
const openai = createOpenAi({ apiKey: process.env.OPENAI_API_KEY! });
API Reference
64 endpoints across 19 groups. Each method mirrors an upstream URL path.
audio
POST openai.v1.audio.speech
POST https://api.openai.com/v1/audio/speech
Cost tier: expensive
const res = await openai.post.v1.audio.speech({ /* ... */ });
POST openai.v1.audio.transcriptions
POST https://api.openai.com/v1/audio/transcriptions
Cost tier: expensive
const res = await openai.post.v1.audio.transcriptions({ /* ... */ });
POST openai.v1.audio.translations
POST https://api.openai.com/v1/audio/translations
Cost tier: expensive
const res = await openai.post.v1.audio.translations({ /* ... */ });
batches
GET openai.v1.batches
GET https://api.openai.com/v1/batches/{idOrOpts}
Cost tier: expensive
const res = await openai.get.v1.batches({ /* ... */ });
POST openai.v1.batches
POST https://api.openai.com/v1/batches
Cost tier: expensive
const res = await openai.post.v1.batches({ /* ... */ });
POST openai.v1.batches.cancel
POST https://api.openai.com/v1/batches/{id}/cancel
Cost tier: expensive
const res = await openai.post.v1.batches.cancel({ /* ... */ });
chat
DELETE openai.v1.chat.completions
DELETE https://api.openai.com/v1/chat/completions/{id}
Cost tier: expensive
const res = await openai.delete.v1.chat.completions({ /* ... */ });
GET openai.v1.chat.completions
GET https://api.openai.com/v1/chat/completions/{idOrOpts}
Cost tier: expensive
const res = await openai.get.v1.chat.completions({ /* ... */ });
GET openai.v1.chat.completions.messages
GET https://api.openai.com/v1/chat/completions/{id}/messages
Cost tier: expensive
const res = await openai.get.v1.chat.completions.messages({ /* ... */ });
POST openai.v1.chat.completions
POST https://api.openai.com/v1/chat/completions/{id}
Cost tier: expensive
const res = await openai.post.v1.chat.completions({ /* ... */ });
codex
GET openai.codex.usage
GET https://chatgpt.com/backend-api/wham/usage
Cost tier: expensive
const res = await openai.get.codex.usage();
completions
POST openai.v1.completions
POST https://api.openai.com/v1/completions
Cost tier: expensive
const res = await openai.post.v1.completions({ /* ... */ });
containers
POST openai.v1.containers
POST https://api.openai.com/v1/containers
Cost tier: expensive
const res = await openai.post.v1.containers({ /* ... */ });
conversations
GET openai.v1.conversations.retrieve
GET https://api.openai.com/v1/conversations/{conversationId}
Cost tier: expensive
const res = await openai.get.v1.conversations.retrieve({ /* ... */ });
POST openai.v1.conversations
POST https://api.openai.com/v1/conversations
Cost tier: expensive
const res = await openai.post.v1.conversations({ /* ... */ });
embeddings
POST openai.v1.embeddings
POST https://api.openai.com/v1/embeddings
Cost tier: expensive
const res = await openai.post.v1.embeddings({ /* ... */ });
evals
POST openai.v1.evals
POST https://api.openai.com/v1/evals
Cost tier: expensive
const res = await openai.post.v1.evals({ /* ... */ });
files
DELETE openai.v1.files
DELETE https://api.openai.com/v1/files/{id}
Cost tier: expensive
const res = await openai.delete.v1.files({ /* ... */ });
GET openai.v1.files
GET https://api.openai.com/v1/files/{idOrOpts}
Cost tier: expensive
const res = await openai.get.v1.files({ /* ... */ });
GET openai.v1.files.content
GET https://api.openai.com/v1/files/{id}/content
Cost tier: expensive
const res = await openai.get.v1.files.content({ /* ... */ });
POST openai.v1.files
POST https://api.openai.com/v1/files
Cost tier: expensive
const res = await openai.post.v1.files({ /* ... */ });
fineTuning
DELETE openai.v1.fineTuning.checkpoints.permissions
DELETE https://api.openai.com/v1/fine_tuning/checkpoints/{checkpoint}/permissions/{permissionId}
Cost tier: expensive
const res = await openai.delete.v1.fineTuning.checkpoints.permissions({ /* ... */ });
GET openai.v1.fineTuning.checkpoints.permissions
GET https://api.openai.com/v1/fine_tuning/checkpoints/{checkpoint}/permissions
Cost tier: expensive
const res = await openai.get.v1.fineTuning.checkpoints.permissions({ /* ... */ });
GET openai.v1.fineTuning.jobs
GET https://api.openai.com/v1/fine_tuning/jobs/{idOrOpts}
Cost tier: expensive
const res = await openai.get.v1.fineTuning.jobs({ /* ... */ });
GET openai.v1.fineTuning.jobs.checkpoints
GET https://api.openai.com/v1/fine_tuning/jobs/{id}/checkpoints
Cost tier: expensive
const res = await openai.get.v1.fineTuning.jobs.checkpoints({ /* ... */ });
GET openai.v1.fineTuning.jobs.events
GET https://api.openai.com/v1/fine_tuning/jobs/{id}/events
Cost tier: expensive
const res = await openai.get.v1.fineTuning.jobs.events({ /* ... */ });
POST openai.v1.fineTuning.checkpoints.permissions
POST https://api.openai.com/v1/fine_tuning/checkpoints/{checkpoint}/permissions
Cost tier: expensive
const res = await openai.post.v1.fineTuning.checkpoints.permissions({ /* ... */ });
POST openai.v1.fineTuning.jobs
POST https://api.openai.com/v1/fine_tuning/jobs
Cost tier: expensive
const res = await openai.post.v1.fineTuning.jobs({ /* ... */ });
POST openai.v1.fineTuning.jobs.cancel
POST https://api.openai.com/v1/fine_tuning/jobs/{id}/cancel
Cost tier: expensive
const res = await openai.post.v1.fineTuning.jobs.cancel({ /* ... */ });
POST openai.v1.fineTuning.jobs.pause
POST https://api.openai.com/v1/fine_tuning/jobs/{id}/pause
Cost tier: expensive
const res = await openai.post.v1.fineTuning.jobs.pause({ /* ... */ });
POST openai.v1.fineTuning.jobs.resume
POST https://api.openai.com/v1/fine_tuning/jobs/{id}/resume
Cost tier: expensive
const res = await openai.post.v1.fineTuning.jobs.resume({ /* ... */ });
images
POST openai.v1.images.edits
POST https://api.openai.com/v1/images/edits
Cost tier: expensive
const res = await openai.post.v1.images.edits({ /* ... */ });
POST openai.v1.images.generations
POST https://api.openai.com/v1/images/generations
Cost tier: expensive
const res = await openai.post.v1.images.generations({ /* ... */ });
POST openai.v1.images.variations
POST https://api.openai.com/v1/images/variations
Cost tier: expensive
const res = await openai.post.v1.images.variations({ /* ... */ });
models
DELETE openai.v1.models
DELETE https://api.openai.com/v1/models/{id}
Cost tier: expensive
const res = await openai.delete.v1.models({ /* ... */ });
GET openai.v1.models
GET https://api.openai.com/v1/models/{id}
Cost tier: expensive
const res = await openai.get.v1.models({ /* ... */ });
moderations
POST openai.v1.moderations
POST https://api.openai.com/v1/moderations
Cost tier: expensive
const res = await openai.post.v1.moderations({ /* ... */ });
organization
GET openai.v1.organization.costs
GET https://api.openai.com/v1/organization/costs
Cost tier: expensive
const res = await openai.get.v1.organization.costs({ /* ... */ });
GET openai.v1.organization.projects
GET https://api.openai.com/v1/organization/projects/{idOrOpts}
Cost tier: expensive
const res = await openai.get.v1.organization.projects({ /* ... */ });
GET openai.v1.organization.projects.rateLimits
GET https://api.openai.com/v1/organization/projects/{projectId}/rate_limits
Cost tier: expensive
const res = await openai.get.v1.organization.projects.rateLimits({ /* ... */ });
GET openai.v1.organization.usage.audioSpeeches
GET https://api.openai.com/v1/organization/usage/audio_speeches
Cost tier: expensive
const res = await openai.get.v1.organization.usage.audioSpeeches({ /* ... */ });
GET openai.v1.organization.usage.audioTranscriptions
GET https://api.openai.com/v1/organization/usage/audio_transcriptions
Cost tier: expensive
const res = await openai.get.v1.organization.usage.audioTranscriptions({ /* ... */ });
GET openai.v1.organization.usage.codeInterpreterSessions
GET https://api.openai.com/v1/organization/usage/code_interpreter_sessions
Cost tier: expensive
const res = await openai.get.v1.organization.usage.codeInterpreterSessions({ /* ... */ });
GET openai.v1.organization.usage.completions
GET https://api.openai.com/v1/organization/usage/completions
Cost tier: expensive
const res = await openai.get.v1.organization.usage.completions({ /* ... */ });
GET openai.v1.organization.usage.embeddings
GET https://api.openai.com/v1/organization/usage/embeddings
Cost tier: expensive
const res = await openai.get.v1.organization.usage.embeddings({ /* ... */ });
GET openai.v1.organization.usage.images
GET https://api.openai.com/v1/organization/usage/images
Cost tier: expensive
const res = await openai.get.v1.organization.usage.images({ /* ... */ });
GET openai.v1.organization.usage.moderations
GET https://api.openai.com/v1/organization/usage/moderations
Cost tier: expensive
const res = await openai.get.v1.organization.usage.moderations({ /* ... */ });
GET openai.v1.organization.usage.vectorStores
GET https://api.openai.com/v1/organization/usage/vector_stores
Cost tier: expensive
const res = await openai.get.v1.organization.usage.vectorStores({ /* ... */ });
realtime
POST openai.v1.realtime.calls
POST https://api.openai.com/v1/realtime/calls
Cost tier: expensive
const res = await openai.post.v1.realtime.calls({ /* ... */ });
POST openai.v1.realtime.calls.hangup
POST https://api.openai.com/v1/realtime/calls/{call_id}/hangup
Cost tier: expensive
const res = await openai.post.v1.realtime.calls.hangup({ /* ... */ });
POST openai.v1.realtime.clientSecrets
POST https://api.openai.com/v1/realtime/client_secrets
Cost tier: expensive
const res = await openai.post.v1.realtime.clientSecrets({ /* ... */ });
responses
DELETE openai.v1.responses
DELETE https://api.openai.com/v1/responses/{id}
Cost tier: expensive
const res = await openai.delete.v1.responses({ /* ... */ });
GET openai.v1.responses
GET https://api.openai.com/v1/responses/{id}
Cost tier: expensive
const res = await openai.get.v1.responses({ /* ... */ });
GET openai.v1.responses.inputItems
GET https://api.openai.com/v1/responses/{id}/input_items
Cost tier: expensive
const res = await openai.get.v1.responses.inputItems({ /* ... */ });
POST openai.v1.responses
POST https://api.openai.com/v1/responses
Cost tier: expensive
const res = await openai.post.v1.responses({ /* ... */ });
POST openai.v1.responses.cancel
POST https://api.openai.com/v1/responses/{id}/cancel
Cost tier: expensive
const res = await openai.post.v1.responses.cancel({ /* ... */ });
POST openai.v1.responses.compact
POST https://api.openai.com/v1/responses/compact
Cost tier: expensive
const res = await openai.post.v1.responses.compact({ /* ... */ });
POST openai.v1.responses.inputTokens
POST https://api.openai.com/v1/responses/input_tokens
Cost tier: expensive
const res = await openai.post.v1.responses.inputTokens({ /* ... */ });
uploads
POST openai.v1.uploads
POST https://api.openai.com/v1/uploads
Cost tier: expensive
const res = await openai.post.v1.uploads({ /* ... */ });
vectorStores
GET openai.v1.vectorStores
GET https://api.openai.com/v1/vector_stores/{idOrOpts}
Cost tier: expensive
const res = await openai.get.v1.vectorStores({ /* ... */ });
GET openai.v1.vectorStores.files
GET https://api.openai.com/v1/vector_stores/{vectorStoreId}/files
Cost tier: expensive
const res = await openai.get.v1.vectorStores.files({ /* ... */ });
POST openai.v1.vectorStores
POST https://api.openai.com/v1/vector_stores
Cost tier: expensive
const res = await openai.post.v1.vectorStores({ /* ... */ });
POST openai.v1.vectorStores.files
POST https://api.openai.com/v1/vector_stores/{vectorStoreId}/files
Cost tier: expensive
const res = await openai.post.v1.vectorStores.files({ /* ... */ });
POST openai.v1.vectorStores.search
POST https://api.openai.com/v1/vector_stores/{vectorStoreId}/search
Cost tier: expensive
const res = await openai.post.v1.vectorStores.search({ /* ... */ });
Middleware
import { createOpenAi, withRetry } from "@apicity/openai";
const openai = createOpenAi({ apiKey: process.env.OPENAI_API_KEY! });
const models = withRetry(openai.get.v1.models, { retries: 3 });
Part of the apicity monorepo.
License
MIT — see LICENSE.