# Is there something wrong with my code? I get error 400

**URL:** <https://community.openai.com/t/is-there-something-wrong-with-my-code-i-get-error-400/105866>\
**Category:** API\
**Created:** [March 18, 2023, 9:15pm UTC](https://community.openai.com/t/is-there-something-wrong-with-my-code-i-get-error-400/105866 "2023-03-18T21:15:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zergatik](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/zergatik/32/44817_2.png) [@zergatik](https://community.openai.com/u/zergatik)\
**Post date:** [March 18, 2023, 9:15pm UTC](https://community.openai.com/t/is-there-something-wrong-with-my-code-i-get-error-400/105866/1 "2023-03-18T21:15:25Z")

</div>

This code was working just fine 2 days ago. Nothing changed on my end but now I am getting error 400 and I can’t figure out why. Help please…

```auto
const myAction = async (tokens, preamble, instructions, prompt) => {

    const axios = require('axios')

    const endpoint = 'https://api.openai.com/v1/completions'

    if (tokens !== undefined) {
      tokens = tokens
    } else {
      tokens = 200
    }

    const inputData = JSON.stringify({
      frequency_penalty: 0.7,
      model: 'text-davinci-003',
      presence_penalty: 1.2,
      stop: [' Human:', ' AI:'],
      prompt: `"${preamble} ${instructions}: ${prompt}"`,
      max_tokens: tokens,
      temperature: 0.5,
      top_p: 1
    })

    const config = {
      method: 'post',
      url: endpoint,
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer myAPIKey'
      },
      data: inputData,
      withCredentials: false
    }

    const result = await axios(config)

    const { data } = result

    temp.chatGPTResponse = data.choices[0].text
  }

  return myAction(args.tokens, args.preamble, args.instructions, args.prompt)

```

---

<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 19, 2023, 1:01am UTC](https://community.openai.com/t/is-there-something-wrong-with-my-code-i-get-error-400/105866/2 "2023-03-19T01:01:17Z")

</div>

Hi @zergatik

You should post the entire response and then you can see the entire error message.

In other words, where you have this:

```js
temp.chatGPTResponse = data.choices[0].text

```

you should do something like this as well so you can review the entire response from the API to asset you debug:

```js
console.log(data)

```

Hope this helps.

🙂

---

<div class="post-metadata">

**Author:** ![EricGT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ericgt/32/20571_2.png) [@EricGT](https://community.openai.com/u/EricGT)\
**Post date:** [December 21, 2023, 10:21am UTC](https://community.openai.com/t/is-there-something-wrong-with-my-code-i-get-error-400/105866/3 "2023-12-21T10:21:17Z")

</div>


