{"id":48839,"library":"openai-fetch","title":"openai-fetch","description":"A minimal and opinionated OpenAI client powered by native fetch (ESM-only, ~14kb). Version 3.4.2 requires Node 18+ or any runtime with built-in fetch. It supports only chat, completions, embeddings, moderations, and TTS endpoints, offering a lean alternative to the official `openai` package (~152kb) that patches fetch. Ships TypeScript types and is actively maintained on GitHub.","status":"active","version":"3.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/dexaai/openai-fetch","tags":["javascript","typescript"],"install":[{"cmd":"npm install openai-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add openai-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add openai-fetch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require is not supported.","wrong":"const OpenAIClient = require('openai-fetch')","symbol":"OpenAIClient","correct":"import { OpenAIClient } from 'openai-fetch'"},{"note":"ChatParams is a type; use import type to avoid runtime errors in TypeScript.","wrong":"import { ChatParams } from 'openai-fetch'","symbol":"type ChatParams","correct":"import type { ChatParams } from 'openai-fetch'"},{"note":"Require is invalid for ESM packages; also, ChatParams is a type, so import type is preferred.","wrong":"const { ChatParams } = require('openai-fetch')","symbol":"ChatParams","correct":"import { ChatParams } from 'openai-fetch'"}],"quickstart":{"code":"import { OpenAIClient } from 'openai-fetch';\n\nconst client = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY ?? '' });\n\nasync function main() {\n  const response = await client.createChatCompletion({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Hello!' }]\n  });\n  console.log(response.choices[0].message?.content);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Demonstrates creating a chat completion using the native fetch client with TypeScript."},"warnings":[{"fix":"Use dynamic import: import('openai-fetch') or switch your project to ESM.","message":"openai-fetch is ESM-only. It cannot be require()'d from CommonJS.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade to Node 18+ or use a fetch polyfill.","message":"Requires Node >= 18 or platform with native fetch. Older Node versions or environments without fetch will throw.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use createCompletion for the singular endpoint.","message":"The client method 'createCompletions' (plural) is deprecated in favor of 'createCompletion' (singular) in v3.0.0? (Check docs).","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Always set OPENAI_API_KEY or pass apiKey option explicitly.","message":"The apiKey is read from process.env.OPENAI_API_KEY if not provided explicitly. If that env var is not set and no key is passed, an error will be thrown.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'14kb':17 '152kb':50 '18':22 '3.4.2':19 'activ':59 'altern':44 'built':28 'built-in':27 'chat':34 'client':9 'complet':35 'embed':36 'endpoint':40 'esm':15 'esm-on':14 'fetch':3,13,30,53 'github':62 'javascript':63 'lean':43 'maintain':60 'minim':5 'moder':37 'nativ':12 'node':21 'offer':41 'offici':47 'openai':2,8,48 'openai-fetch':1 'opinion':7 'packag':49 'patch':52 'power':10 'requir':20 'runtim':25 'ship':54 'support':32 'tts':39 'type':56 'typescript':55,64 'version':18","created_at":"2026-06-07T16:58:44.085052+00:00","updated_at":"2026-06-07T16:58:44.085052+00:00","problems":[{"fix":"import { OpenAIClient } from 'openai-fetch' or use dynamic import.","cause":"Trying to require ESM package in CommonJS module.","error":"Error: The 'openai-fetch' package is ESM only. Use 'import' instead of 'require'."},{"fix":"Upgrade to Node >= 18 or use a fetch polyfill like 'node-fetch'.","cause":"Running in Node < 18 or environment without native fetch.","error":"TypeError: fetch is not a function"},{"fix":"Set OPENAI_API_KEY or pass apiKey in client constructor.","cause":"No apiKey provided and OPENAI_API_KEY not set.","error":"OPENAI_API_KEY must be provided or set as environment variable"},{"fix":"import type { ChatParams } from 'openai-fetch'","cause":"Importing a type as a value.","error":"TypeScript error: 'ChatParams' is a type and must be imported using 'import type'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/dexaai/openai-fetch#readme","github":"https://github.com/dexaai/openai-fetch","docs":null,"changelog":null,"pypi":null,"npm":"openai-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}