{"id":19747048,"url":"https://github.com/backmesh/openai-react-native","last_synced_at":"2025-10-07T12:27:27.163Z","repository":{"id":254759941,"uuid":"847443751","full_name":"backmesh/openai-react-native","owner":"backmesh","description":"OpenAI API React Native Client without polyfills","archived":false,"fork":false,"pushed_at":"2024-09-12T19:19:39.000Z","size":1543,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-28T10:07:26.209Z","etag":null,"topics":["openai-api","react-native"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/openai-react-native","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/backmesh.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":"2024-08-25T20:46:27.000Z","updated_at":"2024-10-20T05:01:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"67bc240a-a2c0-4fea-971c-1bdf52f6ccdd","html_url":"https://github.com/backmesh/openai-react-native","commit_stats":null,"previous_names":["backmesh/openai-react-native"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backmesh%2Fopenai-react-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backmesh%2Fopenai-react-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backmesh%2Fopenai-react-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backmesh%2Fopenai-react-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/backmesh","download_url":"https://codeload.github.com/backmesh/openai-react-native/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224202754,"owners_count":17272807,"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":["openai-api","react-native"],"created_at":"2024-11-12T02:16:45.460Z","updated_at":"2025-10-07T12:27:22.119Z","avatar_url":"https://github.com/backmesh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Open AI React Native Client\n\nThe goal of this library is to use [React Native SSE](https://github.com/binaryminds/react-native-sse) and [Expo FileSystem](https://docs.expo.dev/versions/latest/sdk/filesystem/) instead of polyfills to support calling the OpenAI API directly from React Native with streaming and file upload support. The package uses the same types and API as the [OpenAI Node SDK](https://github.com/openai/openai-node) wherever possible.\n\n\u003e [!CAUTION]\n\u003e You should never expose any secrets in the bundle of a web or mobile app. The correct usage of this client package is with a backend that proxies the OpenAI call while making sure access is secured. The `baseURL` parameter for this OpenAI client is thus mandatory. If you set the baseURL to https://api.openai.com/v1, you are basically exposing your OpenAI API key on the internet! This example in this repo uses [Backmesh](https://backmesh.com).\n\n### Contributions and Feature Requests\n\nIf you would like to contribute or request a feature, please join our [Discord](https://discord.com/invite/FfYyJfgUUY) and ask questions in the **#oss** channel or create a pull request or issue.\n\n### Setup\n\nInstall the package\n\n```bash\nnpm i openai-react-native\n```\n\nAnd then instantiate the client:\n\n```typescript\nimport OpenAI from 'openai-react-native';\n\nconst client = new OpenAI({\n  baseURL:\n    'https://edge.backmesh.com/v1/proxy/PyHU4LvcdsQ4gm2xeniAFhMyuDl2/yWo35DdTROVMT52N0qs4/',\n  // The backmesh proxy uses your auth provider's JWT to authorize access\n  apiKey: supabase.auth.session().access_token,\n});\n```\n\n### Usage\n\nThe streaming APIs uses an [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) from [react-native-sse](https://github.com/binaryminds/react-native-sse) under the hood to provide a required typed `onData` stream event callback and three optional ones: `onDone`, `onOpen` and `onError`.\n\n```typescript\nclient.chat.completions.stream(\n  {\n    model: 'gpt-4o-mini',\n    messages: [{ role: 'user', content: 'Hello, world!' }],\n  },\n  (data) =\u003e {\n    console.log(data.choices[0].delta.content);\n    const content = data.choices[0].delta.content;\n    if (content) {\n      setText((prevText) =\u003e prevText + content); // Handle the streaming completion data here\n    }\n  },\n  {\n    onError: (error) =\u003e {\n      console.error('SSE Error:', error); // Handle any errors here\n    },\n    onOpen: () =\u003e {\n      console.log('SSE connection for completion opened.'); // Handle when the connection is opened\n    },\n  }\n);\n```\n\nThe file upload API is async, requires a `purpose` string and leverages the [Expo File System](https://docs.expo.dev/versions/latest/sdk/filesystem/) so only a filepath needs to be provided.\n\n```typescript\ntry {\n  const filePath = FileSystem.documentDirectory + 'data.pdf'; // Adjust the path as needed\n  const file = await client.files.create(filePath, 'fine-tune');\n  console.log(file);\n} catch (error) {\n  console.error('File creation error:', error);\n}\n```\n\nCheck the [example](https://github.com/backmesh/openai-react-native/blob/main/sample/app/index.tsx) for more details\n\n## Coverage\n\n- [x] [Chat Completion](https://platform.openai.com/docs/api-reference/chat)\n- [x] [Models](https://beta.openai.com/docs/api-reference/models)\n- [x] [Files](https://beta.openai.com/docs/api-reference/files)\n- [x] [Moderations](https://beta.openai.com/docs/api-reference/moderations)\n- [ ] [Images](https://beta.openai.com/docs/api-reference/images)\n- [ ] [Audio](https://platform.openai.com/docs/api-reference/audio)\n- [ ] [Embeddings](https://platform.openai.com/docs/api-reference/embeddings)\n\n## Beta Coverage\n\n- [x] [Threads](https://beta.openai.com/docs/api-reference/threads)\n- [x] [Assistants](https://platform.openai.com/docs/api-reference/assistants)\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackmesh%2Fopenai-react-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbackmesh%2Fopenai-react-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackmesh%2Fopenai-react-native/lists"}