- Notifications
You must be signed in to change notification settings - Fork24
Minimal and opinionated OpenAI client powered by fetch.
License
dexaai/openai-fetch
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A minimal and opinionated OpenAI client powered by fetch.
Unfortunately, the officialopenai package patches fetch in problematic ways and is quite bloated.
- 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-fetchis~14kb andopenaiis~152kb - You only need chat, completions, embeddings, and moderations, and TTS
- 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
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.
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.
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>
The type definitions are avaible through TSServer, and can be found here:type definitions.
MIT ©Dexa
About
Minimal and opinionated OpenAI client powered by fetch.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.