# I am receiving an error status code 400

**URL:** <https://community.openai.com/t/i-am-receiving-an-error-status-code-400/351121>\
**Category:** API\
**Tags:** api\
**Created:** [September 4, 2023, 9:41am UTC](https://community.openai.com/t/i-am-receiving-an-error-status-code-400/351121 "2023-09-04T09:41:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daffa](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@Daffa](https://community.openai.com/u/Daffa)\
**Post date:** [September 4, 2023, 9:41am UTC](https://community.openai.com/t/i-am-receiving-an-error-status-code-400/351121/1 "2023-09-04T09:41:54Z")

</div>

I have made sure that my API key and endpoint link are correct but i am still receiving a 400 error

```auto
import React, { useState } from 'react';
import axios from 'axios';

const OpenAIIntegration = () => {
  const [userInput, setUserInput] = useState('');
  const [apiResponse, setApiResponse] = useState('');
  const apiKey = "sk-abcdef";

  const getOpenAIResponse = async () => {
    try {
      const response = await axios.post(
        '',
        {
          prompt: userInput,
          max_tokens: 200, // Adjust based on your requirements

        },
        {
          headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer ${apiKey}`,
            model:"gpt-3.5-turbo"
          },
        }
      );
      setApiResponse(response.data.choices[0].text);
    } catch (error) {
      console.error('Error making OpenAI API request:', error);
    }
  };

  return (
    <div>
      <input
        type="text"
        value={userInput}
        onChange={(e) => setUserInput(e.target.value)}
      />
      <button onClick={getOpenAIResponse}>Get Response</button>
      <div>API Response: {apiResponse}</div>
    </div>
  );
};

export default OpenAIIntegration;

```

endpoint link is removed and replaced because it can’t be posted but i am using the chat completion endpoint

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [September 4, 2023, 12:43pm UTC](https://community.openai.com/t/i-am-receiving-an-error-status-code-400/351121/2 "2023-09-04T12:43:32Z")

</div>

The Chat completion endpoint is required in order to use gpt-3.5-turbo, and its input is `messages`, not `prompt`, which is a strictly-formatted and validated list of role messages produced per the documentation.

---

<div class="post-metadata">

**Author:** ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)\
**Post date:** [September 4, 2023, 1:05pm UTC](https://community.openai.com/t/i-am-receiving-an-error-status-code-400/351121/3 "2023-09-04T13:05:08Z")

</div>

Hi @Daffa

Welcome to the community.

I’d recommend reading the [docs on chat completion](https://platform.openai.com/docs/guides/gpt/chat-completions-api) as there are discrepancies in the code you shared.

I’d also recommend using the [OpenAI NodeJS library](https://platform.openai.com/docs/libraries/node-js-library).

---

<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/i-am-receiving-an-error-status-code-400/351121/4 "2023-12-21T10:21:38Z")

</div>


