Official Node.js client library


We just released an official Node.js library for the OpenAI API. It’s available to install through npm, and you can find code examples in our API reference.

We hope you find this useful when developing Node.js apps that use our API!


Thank you! Good to see some additional support in nodejs for openai!

Juts one question - I noted that you used the ‘request’ package for the http client vs a package like axios (or even fetch). Are you aware that ‘request’ has been deprecated, and has not been actively maintained in over 2 years?

1 Like

Thanks for your reply!

This project is using the axios package, which you can verify here:

I don’t see a place where we’re using the ‘request’ package, but if you find one please point us to it.

1 Like

Good morning - Apologies! I mistakenly traced openai-node from the npm deployment to

GitHub - jtams/openai-node: A library for using the OpenAI GPT-3 API with Node. … which uses Request.

I can see now the right deployment using Axios is sitting at

1 Like


I tried it but in my tests, I couldn’t find a way to pass the userId string in my API calls. How can I pass this parameter?

I use the openai-api package by Nikita Jerschow. Happy to migrate to the official library in the future :slight_smile:

1 Like

What do you mean by ‘userId string’? If you are referring to the api key, you will be able to access it from your process object on a nodejs server, and pass it that way. Here is the example from the docs:

const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY,});

Thanks for raising this @ediardo. I assume you’re referring to the “user” parameter mentioned in this Provide a user identifier section.

You’re correct that the “user” parameter is not explicitly supported by the current version of this package – typescript will throw and error if you try to pass it. As a temporary workaround, you can cast the request parameters to any in typescript and continue passing it:

const resp = await openai.createCompletion("text-davinci-001", {
    prompt: "Hello world",
    user: "user-1234",
} as any);

We’ll work on getting user natively supported in the next week or so.


Thank you for the prompt reply.

Cool, didn’t know it was this recent. I’m currently using this on my sideprojects :slight_smile: it works great

1 Like

explicit support for the user parameter is added in version 2.0.4