{"_id":"fastify-openai","_rev":"5-e794148ef2ccdbe0d90371e3e407674a","name":"fastify-openai","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"fastify-openai","version":"0.1.0","keywords":["openai","open ai","llm","generative ai","fastify","fastify-plugin"],"author":{"name":"Tim Wheeler","email":"tim@timwheeler.com"},"license":"MIT","_id":"fastify-openai@0.1.0","maintainers":[{"name":"timwheeler","email":"tim@timwheeler.com"}],"homepage":"https://github.com/timmywheels/fastify-openai#readme","bugs":{"url":"https://github.com/timmywheels/fastify-openai/issues"},"tsd":{"directory":"test/types"},"dist":{"shasum":"4599aa7a0b82436e3dfded08ffbda22061dda3bd","tarball":"https://registry.npmjs.org/fastify-openai/-/fastify-openai-0.1.0.tgz","fileCount":8,"integrity":"sha512-YAsHlspni9E0CB9Wb32J9Nt+xMKjiQxBfx50+rXM1vTgOk9AHTTWWeMDlO6hkuHuzyX5t5e3I7LU1LLRnIp+5w==","signatures":[{"sig":"MEUCIQCe2Fyptz/Ii+yxAf0MpTtby6xbBcCMS7gyA8nOYxH9fgIgVcMXMchSEEbHbPSXtNafKQMxGB0lbEJobex4GvMxXkw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":15888},"main":"index.js","types":"index.d.ts","engines":{"node":">=10"},"gitHead":"09b1a6f64165d98ae9547e6240238e27c34d3b9d","scripts":{"lint":"standard --verbose","test":"npm run lint && npm run unit && npm run test:typescript","unit":"tap test/index.test.js","test:ci":"npm run unit:coverage && npm run test:typescript","lint:fix":"standard --fix","coveralls":"cat .tap/report/lcov.info | coveralls","unit:report":"npm run unit -- --coverage-report=html","unit:verbose":"npm run unit -- -Rspec","unit:coverage":"npm run unit -- --coverage-report=lcovonly --no-browser","test:typescript":"tsd"},"_npmUser":{"name":"timwheeler","email":"tim@timwheeler.com"},"repository":{"url":"git+ssh://git@github.com/timmywheels/fastify-openai.git","type":"git"},"_npmVersion":"10.2.4","description":"OpenAI Fastify plugin","directories":{},"_nodeVersion":"20.11.0","dependencies":{"fastify-plugin":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^20.0.0","tsd":"^0.31.2","dotenv":"^16.0.0","openai":"^4.0.0","fastify":"^5.0.0","standard":"^17.0.0","coveralls":"^3.1.1","typescript":"^5.6.3","@types/node":"^22.7.7"},"peerDependencies":{"openai":">=4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/fastify-openai_0.1.0_1729441704640_0.8154242615051019","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"fastify-openai","version":"0.1.1","keywords":["openai","open ai","llm","generative ai","fastify","fastify-plugin"],"author":{"name":"Tim Wheeler","email":"tim@timwheeler.com"},"license":"MIT","_id":"fastify-openai@0.1.1","maintainers":[{"name":"timwheeler","email":"tim@timwheeler.com"}],"homepage":"https://github.com/timmywheels/fastify-openai#readme","bugs":{"url":"https://github.com/timmywheels/fastify-openai/issues"},"tsd":{"directory":"test/types"},"dist":{"shasum":"269e85c63fc8a248f967a905db98e406777fa1fd","tarball":"https://registry.npmjs.org/fastify-openai/-/fastify-openai-0.1.1.tgz","fileCount":9,"integrity":"sha512-f2RQQAx63ispxNvGDbXlHc3qTLTzzym5G+vGWzHHTOYvKMWlTC2CxG5T+PXp7CGyyglpVxMR1Y6ZtpcJOBNmgw==","signatures":[{"sig":"MEUCIQDG3OMDdndNJzCS7thYvsmhHbQHiCaSzZtwoJ1MXZODvwIgDxSkrG+UEXX7Ze1KBjkFuKcm98I5UgM7SVjN9UgX5Nk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17618},"main":"index.js","types":"index.d.ts","engines":{"node":">=10"},"gitHead":"350902b16978b678df1c457522ae885251aa1ae9","scripts":{"lint":"standard --verbose","test":"npm run lint && npm run unit && npm run test:typescript","unit":"tap test/index.test.js","test:ci":"npm run unit:coverage && npm run test:typescript","lint:fix":"standard --fix","coveralls":"cat .tap/report/lcov.info | coveralls","unit:report":"npm run unit -- --coverage-report=html","unit:verbose":"npm run unit -- -Rspec","unit:coverage":"npm run unit -- --coverage-report=lcovonly --no-browser","test:typescript":"tsd"},"_npmUser":{"name":"timwheeler","email":"tim@timwheeler.com"},"repository":{"url":"git+ssh://git@github.com/timmywheels/fastify-openai.git","type":"git"},"_npmVersion":"10.2.4","description":"OpenAI Fastify plugin","directories":{},"_nodeVersion":"20.11.0","dependencies":{"fastify-plugin":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^20.0.0","tsd":"^0.31.2","dotenv":"^16.0.0","openai":"^4.68.1","fastify":"^5.0.0","standard":"^17.0.0","coveralls":"^3.1.1","typescript":"^5.6.3","@types/node":"^22.7.7"},"peerDependencies":{"openai":"^4.68.0"},"_npmOperationalInternal":{"tmp":"tmp/fastify-openai_0.1.1_1729450552762_0.4095904994692612","host":"s3://npm-registry-packages"}},"0.1.2":{"name":"fastify-openai","version":"0.1.2","keywords":["openai","open ai","llm","generative ai","fastify","fastify-plugin"],"author":{"name":"Tim Wheeler","email":"tim@timwheeler.com"},"license":"MIT","_id":"fastify-openai@0.1.2","maintainers":[{"name":"timwheeler","email":"tim@timwheeler.com"}],"homepage":"https://github.com/timmywheels/fastify-openai#readme","bugs":{"url":"https://github.com/timmywheels/fastify-openai/issues"},"tsd":{"directory":"test/types"},"dist":{"shasum":"388a2e44efc6e907b33f672037623d238ca41202","tarball":"https://registry.npmjs.org/fastify-openai/-/fastify-openai-0.1.2.tgz","fileCount":9,"integrity":"sha512-2wMqI39kZu8XEIpzRScWmN+NJC0swzPafkHBDx4sOzQvtWa8rKCm/Pk13ocaZzfuJXe8ZHzcKv4yMbtLwlhIiA==","signatures":[{"sig":"MEQCIHCr/3TD4u/6e8HeEi/ZIrn61tiOos4cU/O/6hPamGwTAiAUCkUbJTY12fgJxl8pBzB1/Lr3/gFrT5XRXxA7XaeLyA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16775},"main":"index.js","types":"index.d.ts","engines":{"node":">=10"},"gitHead":"abe2132713bd05572492d76c8b1ed44749e645eb","scripts":{"lint":"standard --verbose","test":"npm run lint && npm run unit && npm run test:typescript","unit":"tap test/index.test.js","test:ci":"npm run unit:coverage && npm run test:typescript","lint:fix":"standard --fix","coveralls":"cat .tap/report/lcov.info | coveralls","unit:report":"npm run unit -- --coverage-report=html","unit:verbose":"npm run unit -- -Rspec","unit:coverage":"npm run unit -- --coverage-report=lcovonly --no-browser","test:typescript":"tsd"},"_npmUser":{"name":"timwheeler","email":"tim@timwheeler.com"},"repository":{"url":"git+ssh://git@github.com/timmywheels/fastify-openai.git","type":"git"},"_npmVersion":"10.2.4","description":"OpenAI Fastify plugin","directories":{},"_nodeVersion":"20.11.0","dependencies":{"fastify-plugin":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^20.0.0","tsd":"^0.31.2","dotenv":"^16.0.0","openai":"^4.68.1","fastify":"^5.0.0","standard":"^17.0.0","coveralls":"^3.1.1","typescript":"^5.6.3","@types/node":"^22.7.7"},"peerDependencies":{"openai":"^4.68.0"},"_npmOperationalInternal":{"tmp":"tmp/fastify-openai_0.1.2_1729451486751_0.6227741609857278","host":"s3://npm-registry-packages"}},"0.1.3":{"name":"fastify-openai","version":"0.1.3","keywords":["openai","open ai","llm","generative ai","fastify","fastify-plugin"],"author":{"name":"Tim Wheeler","email":"tim@timwheeler.com"},"license":"MIT","_id":"fastify-openai@0.1.3","maintainers":[{"name":"timwheeler","email":"tim@timwheeler.com"}],"homepage":"https://github.com/timmywheels/fastify-openai#readme","bugs":{"url":"https://github.com/timmywheels/fastify-openai/issues"},"tsd":{"directory":"test/types"},"dist":{"shasum":"0b2d2387e9ee0b7a26a02c2660e6880937a0c66c","tarball":"https://registry.npmjs.org/fastify-openai/-/fastify-openai-0.1.3.tgz","fileCount":9,"integrity":"sha512-S2pPTpqrFZtEBbcwY5dXft4GiA5D+iF3viiP7okcf3uX353u5KUrx3+XlAiBDCTqZ0xSRxDVsDaDva5UY3i9Hg==","signatures":[{"sig":"MEYCIQDplWnLtG4EABtyxcvGauTIDYPxEGrAf4UlqAPff3PyewIhAJz6/bR4rO70UL+vXMHZhySansbocbhdMA9iRbx1lTzO","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17143},"main":"index.js","types":"index.d.ts","engines":{"node":">=10"},"gitHead":"0c0462676cbd71c6eba32b2b48644407e24d0d47","scripts":{"lint":"standard --verbose","test":"npm run lint && npm run unit && npm run test:typescript","unit":"tap test/index.test.js","test:ci":"npm run unit:coverage && npm run test:typescript","lint:fix":"standard --fix","coveralls":"cat .tap/report/lcov.info | coveralls","unit:report":"npm run unit -- --coverage-report=html","unit:verbose":"npm run unit -- -Rspec","unit:coverage":"npm run unit -- --coverage-report=lcovonly --no-browser","test:typescript":"tsd"},"_npmUser":{"name":"timwheeler","email":"tim@timwheeler.com"},"repository":{"url":"git+ssh://git@github.com/timmywheels/fastify-openai.git","type":"git"},"_npmVersion":"10.2.4","description":"OpenAI Fastify plugin","directories":{},"_nodeVersion":"20.11.0","dependencies":{"fastify-plugin":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^20.0.0","tsd":"^0.31.2","dotenv":"^16.0.0","openai":"^4.68.1","fastify":"^5.0.0","standard":"^17.0.0","coveralls":"^3.1.1","typescript":"^5.6.3","@types/node":"^22.7.7"},"peerDependencies":{"openai":"^4.68.0"},"_npmOperationalInternal":{"tmp":"tmp/fastify-openai_0.1.3_1729451987491_0.6521058231222985","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"fastify-openai","version":"0.2.0","description":"OpenAI Fastify plugin","main":"index.js","types":"index.d.ts","scripts":{"lint":"standard --verbose","lint:fix":"standard --fix","test":"npm run lint && npm run unit && npm run test:typescript","test:ci":"npm run unit:coverage && npm run test:typescript","test:typescript":"tsd","unit":"tap test/index.test.js","unit:coverage":"npm run unit -- --coverage-report=lcovonly --no-browser","unit:report":"npm run unit -- --coverage-report=html","unit:verbose":"npm run unit -- -Rspec","coveralls":"cat .tap/report/lcov.info | coveralls"},"repository":{"type":"git","url":"git+ssh://git@github.com/timmywheels/fastify-openai.git"},"keywords":["openai","open ai","llm","generative ai","fastify","fastify-plugin"],"author":{"name":"Tim Wheeler","email":"tim@timwheeler.com"},"license":"MIT","bugs":{"url":"https://github.com/timmywheels/fastify-openai/issues"},"homepage":"https://github.com/timmywheels/fastify-openai#readme","engines":{"node":">=10"},"dependencies":{"fastify-plugin":"^5.0.1"},"devDependencies":{"@types/node":"^22.15.2","coveralls":"^3.1.1","dotenv":"^16.0.0","fastify":"^5.3.2","openai":"^4.96.0","standard":"^17.0.0","tap":"^21.1.0","tsd":"^0.31.2","typescript":"^5.8.3"},"peerDependencies":{"openai":"^4.68.0","fastify":"^5.0.0"},"tsd":{"directory":"test/types"},"_id":"fastify-openai@0.2.0","gitHead":"a7765abbf088941e47ba2d2cac61cf309892d60e","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-ScR4zg1RmmTmC+ib2bqfUPpDEc0nqkRXR9v7ZJbPUk7fUqskUJNs+T1lg+CiMCVkexgF1NfsiRZO0P0XNuj7jg==","shasum":"e3bba654e0a664c13721b81b46a8cdc2c4294727","tarball":"https://registry.npmjs.org/fastify-openai/-/fastify-openai-0.2.0.tgz","fileCount":9,"unpackedSize":17169,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD2tTYa8OnSH4F4QUqA9xTD9+xmkCG4SeUfTpQ99rnR3AIhANN+s+BZAYeQxziMQR6nKmARgpgVmKwFoWP6v08KR9Pj"}]},"_npmUser":{"name":"timwheeler","email":"tim@timwheeler.com"},"directories":{},"maintainers":[{"name":"timwheeler","email":"tim@timwheeler.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fastify-openai_0.2.0_1745632553089_0.38776292902278664"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-20T16:28:24.538Z","modified":"2025-04-26T01:55:53.514Z","0.1.0":"2024-10-20T16:28:24.839Z","0.1.1":"2024-10-20T18:55:52.947Z","0.1.2":"2024-10-20T19:11:26.932Z","0.1.3":"2024-10-20T19:19:47.670Z","0.2.0":"2025-04-26T01:55:53.340Z"},"bugs":{"url":"https://github.com/timmywheels/fastify-openai/issues"},"author":{"name":"Tim Wheeler","email":"tim@timwheeler.com"},"license":"MIT","homepage":"https://github.com/timmywheels/fastify-openai#readme","keywords":["openai","open ai","llm","generative ai","fastify","fastify-plugin"],"repository":{"type":"git","url":"git+ssh://git@github.com/timmywheels/fastify-openai.git"},"description":"OpenAI Fastify plugin","maintainers":[{"name":"timwheeler","email":"tim@timwheeler.com"}],"readme":"# fastify-openai\n\n[![NPM version](https://img.shields.io/npm/v/fastify-openai.svg?style=flat)](https://www.npmjs.com/package/fastify-openai)\n[![GitHub CI](https://github.com/timmywheels/fastify-openai/workflows/GitHub%20CI/badge.svg)](https://github.com/timmywheels/fastify-openai/actions?workflow=GitHub+CI)\n[![Coverage Status](https://coveralls.io/repos/github/timmywheels/fastify-openai/badge.svg?branch=main)](https://coveralls.io/github/timmywheels/fastify-openai?branch=main)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\n\n[OpenAI Node.js Library](https://github.com/openai/openai-node) instance initialization and encapsulation for the [Fastify](https://github.com/fastify/fastify) framework.\n\n## Install\n\nInstall the package:\n\n```sh\n# npm\nnpm i fastify-openai\n\n# yarn\nyarn add fastify-openai\n\n# pnpm\npnpm add fastify-openai\n\n# bun\nbun add fastify-openai\n```\n\n## Usage\n\nThe package needs to be added to your project with `register` and you must at least configure your account's secret key wich is available in your [OpenAI Dashboard](https://platform.openai.com/docs/api-reference/api-keys) then call the [OpenAI](https://github.com/openai/openai-node) API and you are done.\n\n#### Importing the package\n\n```js\n// ESM\nimport fastifyOpenAI from \"fastify-openai\";\n\n// CJS\nconst fastifyOpenAI = require(\"fastify-openai\");\n```\n\n#### JavaScript + CJS\n\n```js\nconst fastify = require(\"fastify\")({ logger: true });\n\nfastify.register(require(\"fastify-openai\"), {\n  apiKey: \"sk-TacO...\",\n});\n\nfastify.post(\"/chat\", async (request, reply) => {\n  // create a chat completion using the OpenAI API\n  const chat = await fastify.openai.chat.completions.create({\n    messages: [{ role: \"user\", content: \"Hello, Fastify!\" }],\n    model: \"gpt-4o-mini\",\n  });\n\n  return chat;\n});\n\nfastify.listen({ port: 3000 });\n```\n\n#### TypeScript + ESM\n\n```ts\nimport Fastify from \"fastify\";\nimport fastifyOpenAI from \"fastify-openai\";\n\nconst fastify = Fastify({ logger: true });\n\nfastify.register(fastifyOpenAI, {\n  apiKey: \"sk-TacO...\",\n});\n\nfastify.post(\"/chat\", async (request, reply) => {\n  // create a chat completion using the OpenAI API\n  const chat = await fastify.openai.chat.completions.create({\n    messages: [{ role: \"user\", content: \"Hello, Fastify!\" }],\n    model: \"gpt-4o-mini\",\n  });\n  return chat;\n});\n\nfastify.listen({ port: 3000 });\n\n// typescript declaration merging\ndeclare module \"fastify\" {\n  interface FastifyInstance {\n    openai: FastifyOpenAI;\n  }\n}\n```\n\n### Options\n\n- `apiKey` **[ required ]**: Your account's secret key wich is available in your [OpenAI Dashboard](https://platform.openai.com/api-keys)\n\n- `name` **[ optional ]**: Through this option `fastify-openai` lets you define multiple OpenAI instances, with different configurations.\n\n- `organization` **[ optional ]**: The organization ID to use for this request. If not provided, the request will be made with the default organization.\n\n- `project` **[ optional ]**: The project ID to use for this request. If not provided, the request will be made with the default project.\n\n- `baseURL` **[ optional ]**: The base URL for the API. Defaults to `https://api.openai.com/v1`.\n\n- `timeout` **[ optional ]**: The request timeout in milliseconds.\n\n- `httpAgent` **[ optional ]**: An HTTP agent used to manage HTTP(S) connections.\n\n- `maxRetries` **[ optional ]**: The maximum number of retries for a request.\n\n### Multiple plugin instances (TypeScript + ESM)\n\nWhen using multiple plugin instances, the `name` property is required for each instance.\n\n```js\nimport Fastify from \"fastify\";\nimport fastifyOpenAI from \"fastify-openai\";\n\nconst fastify = Fastify({ logger: true });\n\nfastify\n  .register(require(\"fastify-openai\"), {\n    apiKey: \"sk-Te5t...\",\n    name: \"test\",\n    timeout: 28000, // in ms (this is 28 seconds)\n  })\n  .register(require(\"fastify-openai\"), {\n    apiKey: \"sk-Pr0d...\",\n    name: \"prod\",\n  });\n\nfastify.post(\"/test/chat\", function (request, reply) {\n  // create a chat completion using the OpenAI API 'test' instance\n  const testChat = await fastify.openai.test.chat.completions.create({\n    messages: [{ role: \"user\", content: \"Hello, Test!\" }],\n    model: \"gpt-4o-mini\",\n  });\n  return testChat;\n});\n\nfastify.post(\"/prod/chat\", function (request, reply) {\n  // create a chat completion using the OpenAI API 'prod' instance\n  const prodChat = await fastify.openai.prod.chat.completions.create({\n      messages: [{ role: \"user\", content: \"Hello, Production!\" }],\n      model: \"gpt-4o-mini\",\n    });\n  return prodChat;\n});\n\nfastify.listen({ port: 3000 });\n\n// typescript declaration merging\ndeclare module \"fastify\" {\n  interface FastifyInstance {\n    openai: {\n      test: FastifyOpenAI;\n      prod: FastifyOpenAI;\n    }\n  }\n}\n```\n\n## Documentation\n\nSee the [Node OpenAI API docs](https://platform.openai.com/docs/api-reference/introduction).\n\n## Acknowledgements\n\nThis project is kindly sponsored by [@timmywheels](https://www.timwheeler.com).\n\n## License\n\nLicensed under [MIT](https://github.com/timmywheels/fastify-openai/blob/main/LICENSE)\n","readmeFilename":"README.md"}