I am running an OpenAI Quickstart tutorial: https://platform.openai.com/docs/quickstart?context=node
Having an issue in Step 3, Making an API request.
When I run: node openai-test.js I get this error:
“TypeError: Cannot read properties of undefined (reading ‘completions’)
at main (C:\Users\leonm\Documents\Study\OpenAi\openai-test.js:7:40)
at Object. (C:\Users\leonm\Documents\Study\OpenAi\openai-test.js:15:1)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49”
I am running the code in VSC terminal.
openai-test.js file is created in local folder, in OpenAi directory.
Node is installed using Command Prompt in C:\WINDOWS\system32
When I run the code as it is at the docs, I get another error.
import OpenAI from "openai";
const openai = new OpenAI();
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: "You are a helpful assistant." }],
model: "gpt-3.5-turbo",
});
console.log(completion.choices[0]);
}
main();
I get the error:
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:77:18)
at wrapSafe (node:internal/modules/cjs/loader:1288:20)
at Module._compile (node:internal/modules/cjs/loader:1340:27)
at Module._extensions…js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
I got it fixed and now both versions of code are working.
This instruction in Quickstart tutorial threw me off:
npm install --save openai
# or
yarn add openai
It should say:
npm install --save openai
# or/and
npm add openai
However, I get a new error:
“RateLimitError: 429 You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs”
Is there any sandbox account to try API or do I necessary have to pay for it even when developing and testing?
Yes, the API is pay per use, paying for the data sent and received, billed at the rate of the AI model. OpenAI Pricing
Outside of free trial monetary grants that may have been issued to accounts under different programs, there is no differentiation of “developing and testing”.