Discord bot - image generation (code 400)

Hello, i have an annoying problem.
I have such a code:

 const configuration = new Configuration({
      apiKey: "OpenAI key"
    });
    const openai = new OpenAIApi(configuration);
    const response = await openai.createImage({
      prompt: "a white siamese cat",
      n: 1,
      size: "1024x1024",
    });
    
    data.result = response['data'][0]['url']
    console.log(data.result)

when i type the command i get this error:

Error: Request failed with status code 400
    at createError (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\adapters\http.js:322:11)   
    at IncomingMessage.emit (node:events:538:35)
    at endReadableNT (node:internal/streams/readable:1342:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Is anyone able to help me? I’ve tried everything and it still doesn’t work…

Maybe debug as follows:

const configuration = new Configuration({
      apiKey: "OpenAI key"
    });
    console.log(configuration)
    const openai = new OpenAIApi(configuration);
    console.log(openai)
    const response = await openai.createImage({
      prompt: "a white siamese cat",
      n: 1,
      size: "1024x1024",
    });
    console.log(response)
    
    //data.result = response['data'][0]['url']
    //console.log(data.result)

When i log only configuration i have this:

Configuration {
  apiKey: 'API key',
  organization: undefined,
  username: undefined,
  password: undefined,
  accessToken: undefined,
  basePath: undefined,
  baseOptions: {
    headers: {
      'User-Agent': 'OpenAI/NodeJS/3.1.0',
      Authorization: 'auth'
    }
  },
  formDataCtor: [Function: FormData] {
    LINE_BREAK: '\r\n',
    DEFAULT_CONTENT_TYPE: 'application/octet-stream'
  }
}

but when i put all this code it
gets the same problem:

OpenAIApi {
  basePath: 'https://api.openai.com/v1',
  axios: <ref *1> [Function: wrap] {
    request: [Function: wrap],
    getUri: [Function: wrap],
    delete: [Function: wrap],
    get: [Function: wrap],
    head: [Function: wrap],
    options: [Function: wrap],
    post: [Function: wrap],
    put: [Function: wrap],
    patch: [Function: wrap],
    defaults: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      headers: [Object]
    },
    interceptors: { request: [InterceptorManager], response: [InterceptorManager] },
    create: [Function: create],
    Axios: [Function: Axios],
    Cancel: [Function: Cancel],
    CancelToken: [Function: CancelToken] { source: [Function: source] },
    isCancel: [Function: isCancel],
    VERSION: '0.26.1',
    all: [Function: all],
    spread: [Function: spread],
    isAxiosError: [Function: isAxiosError],
    default: [Circular *1]
  },
  
  }
}
Error: Request failed with status code 400
    at createError (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\LORC1\OneDrive\Pulpit\Nowy folder\node_modules\openai\node_modules\axios\lib\adapters\http.js:322:11)   
    at IncomingMessage.emit (node:events:538:35)
    at endReadableNT (node:internal/streams/readable:1342:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Does this help debug (change approach a bit)?

 const generateImage = async () => {
    const imageParameters = {
      prompt: userPrompt,
      n:1,
      size: "256x256",
    }
    const response = await openai.createImage(imageParameters);
    const urlData = response.data.data[0].url;
    console.log("urlData =",urlData);
    setImageUrl(urlData);
  }

Just a stab in the dark @3XT . Sorry if not helpful or a waste of time. I only interact with the OpenAI API with Ruby, so I’ll drop off and let the Javascript folks help you :slight_smile: