{"id":25066819,"url":"https://github.com/dexaai/openai-fetch","last_synced_at":"2025-04-08T09:05:08.606Z","repository":{"id":62075105,"uuid":"556932398","full_name":"dexaai/openai-fetch","owner":"dexaai","description":"Minimal and opinionated OpenAI client powered by fetch.","archived":false,"fork":false,"pushed_at":"2025-01-07T21:51:27.000Z","size":828,"stargazers_count":184,"open_issues_count":3,"forks_count":21,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-04T05:42:34.785Z","etag":null,"topics":["cloudflare-workers","deno","fetch-api","gpt-3","nodejs","openai","openai-api","openai-gpt3","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dexaai.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-24T19:41:12.000Z","updated_at":"2025-03-08T17:02:02.000Z","dependencies_parsed_at":"2024-04-21T13:54:38.735Z","dependency_job_id":"3001a490-4461-4298-a6d3-198b3cc250c8","html_url":"https://github.com/dexaai/openai-fetch","commit_stats":null,"previous_names":["dexaai/openai-fetch","rileytomasek/openai-fetch"],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexaai%2Fopenai-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexaai%2Fopenai-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexaai%2Fopenai-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexaai%2Fopenai-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dexaai","download_url":"https://codeload.github.com/dexaai/openai-fetch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809963,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","deno","fetch-api","gpt-3","nodejs","openai","openai-api","openai-gpt3","typescript"],"created_at":"2025-02-06T20:28:13.466Z","updated_at":"2025-04-08T09:05:08.588Z","avatar_url":"https://github.com/dexaai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAI Fetch Client\n\n[![Build Status](https://github.com/rileytomasek/openai-fetch/actions/workflows/main.yml/badge.svg)](https://github.com/rileytomasek/openai-fetch/actions/workflows/main.yml) [![npm version](https://img.shields.io/npm/v/openai-fetch.svg?color=0c0)](https://www.npmjs.com/package/openai-fetch)\n\nA minimal and opinionated OpenAI client powered by fetch.\n\nUnfortunately, the official [openai](https://github.com/openai/openai-node) package patches fetch in problematic ways and is quite bloated.\n\n### Reasons to consider using `openai-fetch`:\n\n- You want a fast and small client that doesn't patch fetch\n- Supports all envs with native fetch: Node 18+, browsers, Deno, Cloudflare Workers, etc\n- Package size: `openai-fetch` is [~14kb](https://bundlephobia.com/package/openai-fetch) and `openai` is [~152kb](https://bundlephobia.com/package/openai)\n- You only need chat, completions, embeddings, and moderations, and TTS\n\n### Use the official `openai` package if:\n\n- Your runtime doesn't have native fetch support\n- Your app can't handle native ESM code\n- You need endpoints other than chat, completions, embeddings, and moderations, and TTS\n- You aren't concerned with lib size or fetch patching\n\n## Install\n\n```bash\nnpm install openai-fetch\n```\n\nThis package requires `node \u003e= 18` or an environment with `fetch` support.\n\nThis package exports [ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). If your project uses CommonJS, consider switching to ESM or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function.\n\n## Usage\n\n```ts\nimport { OpenAIClient } from 'openai-fetch';\n\nconst client = new OpenAIClient({ apiKey: '\u003cyour api key\u003e' });\n```\n\nThe `apiKey` is optional and will be read from `process.env.OPENAI_API_KEY` if present.\n\n## API\n\nThe API follows OpenAI very closely, so their [reference documentation](https://platform.openai.com/docs/api-reference) can generally be used. Everything is strongly typed, so you will know if anything is different as soon as TypeScript parses your code.\n\n```ts\n// Generate a single chat completion\nclient.createChatCompletion(params: ChatParams): Promise\u003cChatResponse\u003e;\n\n// Stream a single completion via a ReadableStream\nclient.streamChatCompletion(params: ChatStreamParams): Promise\u003cChatStreamResponse\u003e;\n\n// Generate one or more completions\nclient.createCompletions(params: CompletionParams): Promise\u003cCompletionResponse\u003e;\n\n// Stream a single completion via a ReadableStream\nclient.streamCompletion(params: CompletionStreamParams): Promise\u003cCompletionStreamResponse\u003e;\n\n// Generate one or more embeddings\nclient.createEmbeddings(params: EmbeddingParams): Promise\u003cEmbeddingResponse\u003e\n\n// Checks for potentially harmful content\nclient.createModeration(params: ModerationParams): Promise\u003cModerationResponse\u003e\n\n// Text-to-Speech\nclient.createSpeech(params: SpeechParams): Promise\u003cSpeechResponse\u003e\n```\n\n### Type Definitions\n\nThe type definitions are avaible through TSServer, and can be found here: [type definitions](/src/types.ts).\n\n## License\n\nMIT © [Dexa](https://dexa.ai)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdexaai%2Fopenai-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdexaai%2Fopenai-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdexaai%2Fopenai-fetch/lists"}