Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 27, 2025. It is now read-only.
/openai-fetchPublic archive

Minimal and opinionated OpenAI client powered by fetch.

License

NotificationsYou must be signed in to change notification settings

dexaai/openai-fetch

Repository files navigation

Build Statusnpm version

A minimal and opinionated OpenAI client powered by fetch.

Unfortunately, the officialopenai package patches fetch in problematic ways and is quite bloated.

Reasons to consider usingopenai-fetch:

  • You want a fast and small client that doesn't patch fetch
  • Supports all envs with native fetch: Node 18+, browsers, Deno, Cloudflare Workers, etc
  • Package size:openai-fetch is~14kb andopenai is~152kb
  • You only need chat, completions, embeddings, and moderations, and TTS

Use the officialopenai package if:

  • Your runtime doesn't have native fetch support
  • Your app can't handle native ESM code
  • You need endpoints other than chat, completions, embeddings, and moderations, and TTS
  • You aren't concerned with lib size or fetch patching

Install

npm install openai-fetch

This package requiresnode >= 18 or an environment withfetch support.

This package exportsESM. If your project uses CommonJS, consider switching to ESM or use thedynamicimport() function.

Usage

import{OpenAIClient}from'openai-fetch';constclient=newOpenAIClient({apiKey:'<your api key>'});

TheapiKey is optional and will be read fromprocess.env.OPENAI_API_KEY if present.

API

The API follows OpenAI very closely, so theirreference documentation can generally be used. Everything is strongly typed, so you will know if anything is different as soon as TypeScript parses your code.

// Generate a single chat completionclient.createChatCompletion(params:ChatParams):Promise<ChatResponse>;// Stream a single completion via a ReadableStreamclient.streamChatCompletion(params:ChatStreamParams):Promise<ChatStreamResponse>;// Generate one or more completionsclient.createCompletions(params:CompletionParams):Promise<CompletionResponse>;// Stream a single completion via a ReadableStreamclient.streamCompletion(params:CompletionStreamParams):Promise<CompletionStreamResponse>;// Generate one or more embeddingsclient.createEmbeddings(params:EmbeddingParams):Promise<EmbeddingResponse>// Checks for potentially harmful contentclient.createModeration(params:ModerationParams):Promise<ModerationResponse>// Text-to-Speechclient.createSpeech(params:SpeechParams):Promise<SpeechResponse>

Type Definitions

The type definitions are avaible through TSServer, and can be found here:type definitions.

License

MIT ©Dexa

About

Minimal and opinionated OpenAI client powered by fetch.

Topics

Resources

License

Stars

Watchers

Forks

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp