# ChatGPT API response : choices: \[ \[Object\] \],

**URL:** <https://community.openai.com/t/chatgpt-api-response-choices-object/94677>\
**Category:** ChatGPT\
**Created:** [March 11, 2023, 9:24pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677 "2023-03-11T21:24:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah.salah.rizk](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sarah.salah.rizk/32/42086_2.png) [@sarah.salah.rizk](https://community.openai.com/u/sarah.salah.rizk)\
**Post date:** [March 11, 2023, 9:24pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/1 "2023-03-11T21:24:29Z")

</div>

hello,  
i was trying simple req/res from chatGPT openai api and i got this:

data: {  
id: ‘cmpl-6t0toKrE5sSwubu4uGmg5iURXyT30’,  
object: ‘text\_completion’,  
created: 1678569516,  
model: ‘text-davinci-003’,  
choices: [[Object] ],  
usage: { prompt\_tokens: 1, completion\_tokens: 16, total\_tokens: 17 }

any idea how to return the response? it should be in choices

code i use below:

const { Configuration, OpenAIApi } = require(“openai”);

const configuration = new Configuration({  
apiKey: ‘\*\*\*\*\*\*\*\*\*’  
});  
const openai = new OpenAIApi(configuration);

async function runChatGpt() {  
const response = await openai.createCompletion({  
model: “text-davinci-003”,  
prompt: “hi”  
});  
console.log(response);  
}

runChatGpt();

---

<div class="post-metadata">

**Author:** ![wfhbrian](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/wfhbrian/32/19388_2.png) [@wfhbrian](https://community.openai.com/u/wfhbrian)\
**Post date:** [March 11, 2023, 9:56pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/2 "2023-03-11T21:56:24Z")

</div>

To start, it sounds like your think you’re using the ChatGPT API but you’re actually using `text-davinci-003`, which may be causing some of your confusion.

---

<div class="post-metadata">

**Author:** ![sarah.salah.rizk](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sarah.salah.rizk/32/42086_2.png) [@sarah.salah.rizk](https://community.openai.com/u/sarah.salah.rizk)\
**Post date:** [March 11, 2023, 10:01pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/3 "2023-03-11T22:01:56Z")

</div>

thanks, but why i got choices: [[Object] ], ? why the choices is undefined?

---

<div class="post-metadata">

**Author:** ![wfhbrian](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/wfhbrian/32/19388_2.png) [@wfhbrian](https://community.openai.com/u/wfhbrian)\
**Post date:** [March 11, 2023, 10:07pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/4 "2023-03-11T22:07:27Z")

</div>

What you’re describing is correct for the model you’re using. You have to access the first object with choices[0].

---

<div class="post-metadata">

**Author:** ![sarah.salah.rizk](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sarah.salah.rizk/32/42086_2.png) [@sarah.salah.rizk](https://community.openai.com/u/sarah.salah.rizk)\
**Post date:** [March 11, 2023, 10:11pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/5 "2023-03-11T22:11:27Z")

</div>

thank you again, but i dont think so, as when i tried for example : “console.log(response.choices[0].text);”  
i got an error that : Cannot read properties of undefined (reading ‘0’) because the choices object is undefined

---

<div class="post-metadata">

**Author:** ![sarah.salah.rizk](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sarah.salah.rizk/32/42086_2.png) [@sarah.salah.rizk](https://community.openai.com/u/sarah.salah.rizk)\
**Post date:** [March 11, 2023, 10:57pm UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/6 "2023-03-11T22:57:36Z")

</div>

i have edit the code to this , and now its working

const { Configuration, OpenAIApi } = require(“openai”);

const config = new Configuration({  
apiKey: “\*\*\*\*\*\*\*”,  
});

const openai = new OpenAIApi(config);

const runChat = async () =\> {  
const prompt = “hi”;

```
const response = await openai.createCompletion({
    model: "text-davinci-003",
    prompt: prompt,
    max_tokens: 2048,
    temperature: .6,
});
    
console.log(response.data.choices[0].text);

```

};

runChat();

---

<div class="post-metadata">

**Author:** ![ruby\_coder](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ruby_coder/32/19875_2.png) [@ruby\_coder](https://community.openai.com/u/ruby_coder)\
**Post date:** [March 12, 2023, 1:10am UTC](https://community.openai.com/t/chatgpt-api-response-choices-object/94677/7 "2023-03-12T01:10:46Z")

</div>

> [@sarah.salah.rizk](#):
>
> `response.data.choices[0].text`

Correct (above)

You @sarah.salah.rizk were mistakenly trying to access the text before:

> [@sarah.salah.rizk](#):
>
> `response.choices[0].text`

Glad you figured it out @sarah.salah.rizk

🙂
