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

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…

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

    const axios = require('axios')

    const endpoint = ''

    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)

Hi @zergatik

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

In other words, where you have this:

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:


Hope this helps.


1 Like