# SyntaxError: The requested module 'openai' does not provide an export named 'OpenAIApi'

**URL:** <https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469>\
**Category:** API\
**Created:** [January 5, 2024, 2:43pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469 "2024-01-05T14:43:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pessonoessono](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/pessonoessono/32/148018_2.png) [@pessonoessono](https://community.openai.com/u/pessonoessono)\
**Post date:** [January 5, 2024, 2:43pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/1 "2024-01-05T14:43:44Z")

</div>

Hi I’m working on a project and I have this error message : import { Configuration, OpenAIApi } from “openai”;  
^^^^^^^^^  
SyntaxError: The requested module ‘openai’ does not provide an export named ‘OpenAIApi’  
at ModuleJob.\_instantiate (internal/modules/esm/module\_job.js:92:21)  
at async ModuleJob.run (internal/modules/esm/module\_job.js:107:20)  
at async Loader.import (internal/modules/esm/loader.js:179:24)  
[nodemon] app crashed - waiting for file changes before starting…

This is the code :

```auto
import express from "express";
import * as dotenv from "dotenv";
import cors from "cors";
import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
    apiKey: "",
});

const openai = new OpenAIApi(configuration);

const app = express();
app.use(cors());
app.use(express.json());

app.get("/", async (req, res) => {
    res.status(200).send({
        message: "Hi Patrick! Welcome to ChatGPT",
    });
});

app.post("/", async (req, res) => {
    try {
        const prompt = req.body.prompt;

        const response = await openai.createCompletion({
            model: "text-davinci-003",
            prompt: `${prompt}`,
            max_tokens: 3000,
            top_p: 1,
            frequency_penalty: 0.5,
            presence_penalty: 0,
        });

        res.status(200).send({
            bot: response.data.choices[0].text,
        });
    } catch (error) {
        console.log(error);
        res.status(500).send(error || "Something went very wrong");
    }
});

app.listen(3000, () =>
console.log("AI server started on port: http//localhost: 3000")
);

Can you help me?`Preformatted text`

```

---

<div class="post-metadata">

**Author:** ![Diet](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/diet/32/562749_2.png) [@Diet](https://community.openai.com/u/Diet)\
**Post date:** [January 5, 2024, 3:52pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/2 "2024-01-05T15:52:41Z")

</div>

Hi! Welcome to the forum!

Could you kindly edit your post and use the preformatted text tool (or simply wrap your code in ``` )

 ![image](https://us1.discourse-cdn.com/openai1/original/4X/c/d/d/cdd7190a31b30f80c6642eb2ce89c40fdaba84ce.png)

Edit: that said, why not use OpenAI like the playground generates for you?

```auto
import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const response = await openai.completions.create({
  model: "gpt-3.5-turbo-instruct",
  prompt: "Hi!\n\n",
  temperature: 1,
  max_tokens: 256,
  top_p: 1,
  frequency_penalty: 0,
  presence_penalty: 0,
});

```

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [January 5, 2024, 5:27pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/3 "2024-01-05T17:27:21Z")

</div>

> [@pessonoessono](#):
>
> ```auto
> const response = await openai.createCompletion({
> model: "text-davinci-003",
> 
> ```

This is using an obsolete AI model and wrong method, likely for the wrong endpoint for the application.

Did an AI write this?

Try API Reference on the sidebar of this forum for modern model marvels and coding methods.

* * *

(The shown AI model is now past its permanent shutdown time everywhere in the world but still saying hello…)  
 ![image](https://us1.discourse-cdn.com/openai1/original/4X/d/d/4/dd43ce7cd03f1d86a8436f657d6856674fc32811.png)

---

<div class="post-metadata">

**Author:** ![pessonoessono](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/pessonoessono/32/148018_2.png) [@pessonoessono](https://community.openai.com/u/pessonoessono)\
**Post date:** [January 5, 2024, 7:03pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/4 "2024-01-05T19:03:08Z")

</div>

This is the new error message const openai = new OpenAI({  
^

TypeError: OpenAI is not a constructor  
at file:///Users/user/Downloads/chatGPT-Zaamu/server/server.js:7:16  
at ModuleJob.run (internal/modules/esm/module\_job.js:110:37)  
at async Loader.import (internal/modules/esm/loader.js:179:24)

This is my new code : `

```auto
import express from "express";
import * as dotenv from "dotenv";
import cors from "cors";
import OpenAI from "openai";

// Utilisez un seul nom de variable pour l'instanciation de la classe OpenAI
const openai = new OpenAI({
    apiKey: "",
});

const app = express();
app.use(cors());
app.use(express.json());

app.get("/", async (req, res) => {
    res.status(200).send({
        message: "Hi Patrick! Welcome to ChatGPT",
    });
});

app.post("/", async (req, res) => {
    try {
        const prompt = req.body.prompt;

        const response = await openai.completions.create({
            model: "gpt-3.5-turbo-instruct",
            prompt: `${prompt}`,
            max_tokens: 3000,
            top_p: 1,
            frequency_penalty: 0.5,
            presence_penalty: 0,
        });

        res.status(200).send({
            bot: response.data.choices[0].text,
        });
    } catch (error) {
        console.log(error);
        res.status(500).send(error || "Something went very wrong");
    }
});

app.listen(3000, () =>
    console.log("AI server started on port: http//localhost:3000")
);`

```

---

<div class="post-metadata">

**Author:** ![Diet](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/diet/32/562749_2.png) [@Diet](https://community.openai.com/u/Diet)\
**Post date:** [January 5, 2024, 7:20pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/5 "2024-01-05T19:20:09Z")

</div>

> [@pessonoessono](#):
>
> ` Patrick! Welcome to ChatGPT`

hmm. works on my machine 🤔

 ![image](https://us1.discourse-cdn.com/openai1/original/4X/f/1/5/f154112a410759ca4d358f72f698325f2425e8e9.png)

what version are you using?

I tried with ` "openai": "4.24.1",`

all that said

I’m not a fan of the libs. In production, we use axios.

---

<div class="post-metadata">

**Author:** ![pessonoessono](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/pessonoessono/32/148018_2.png) [@pessonoessono](https://community.openai.com/u/pessonoessono)\
**Post date:** [January 5, 2024, 8:03pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/6 "2024-01-05T20:03:17Z")

</div>

the project requested version “openai”: “^3.1.0”

---

<div class="post-metadata">

**Author:** ![Diet](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/diet/32/562749_2.png) [@Diet](https://community.openai.com/u/Diet)\
**Post date:** [January 5, 2024, 8:11pm UTC](https://community.openai.com/t/syntaxerror-the-requested-module-openai-does-not-provide-an-export-named-openaiapi/578469/7 "2024-01-05T20:11:11Z")

</div>

is there anything that prevents you from updating?
