31
Views
5
Comments
Solved
calling openAi with a POST, but getting 400 bad request

Good morning,

I was trying to implement a call to openAi on my reactive webb app. I need AI to read an incoming email, scan key words, summaryze the content, define the task needed and send the email to the right office. Every time I ty to do a POST API call, I get different errors, and 400 is the main one. When I managed, (I dont't know how, since I've been revising the same process over and over again doing alwas the same things), to get 200 ok, it returned nothing. 




Screenshot 2025-06-12 094005.png
Screenshot 2025-06-06 105717.png
Screenshot 2025-06-11 151114.png
2026-01-28 16-57-48
Mihai Melencu
Champion
Solution

Hi, I just tested your body payload and it works on my end. Make sure your headers are set correctly:


2024-04-08 12-58-25
Shady Mansour
Solution

Hi Anna,  i attached here OML for your request you can check the logic yourself and remember to put you own authorization key.. 


ChatOpenAI(1).oml
2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @Anna Viola De Matteis ,

Based on the error you're seeing in Postman, it looks like you're missing the model field in your request body. This field is required. According to OpenAI's documentation, the model parameter specifies which model should generate the response, for example, gpt-4o or gpt-3.5-turbo. Make sure to include it in your JSON payload. 

Here you can find all the models available: Models | OpenAI API .

Also here is an example for the request body:

model": "gpt-4.1",

    "messages": [

      {

        "role": "developer",

        "content": "You are a helpful assistant."

      },

      {

        "role": "user",

        "content": "Hello!"

      }

    ]

  }'

API Reference: Chat | OpenAI API

UserImage.jpg
Anna Viola Viola De Matteis

Hi, thank you for the answer. However, I did specify every field required. This is the Request Body:


{  "model": "gpt-4",  "temperature": 0.2,  "messages": [    {      "role": "system",      "content": "Agisci come un assistente che crea task per la Pubblica Amministrazione da email testuali. Rispondi solo in JSON."    },    {      "role": "user",      "content": "Genera un task da questa email:\nOggetto: Richiesta sistemazione lampione\nCorpo: Buongiorno, segnalo che il lampione davanti a via Roma 45 è guasto da giorni. Potete intervenire?\n\nUffici disponibili:\n- Ufficio Tecnico: manutenzione e segnalazioni strutturali\n- Ufficio Ambiente: gestione del verde pubblico e rifiuti"    }  ]}

2026-01-28 16-57-48
Mihai Melencu
Champion
Solution

Hi, I just tested your body payload and it works on my end. Make sure your headers are set correctly:


UserImage.jpg
Anna Viola Viola De Matteis
2024-04-08 12-58-25
Shady Mansour
Solution

Hi Anna,  i attached here OML for your request you can check the logic yourself and remember to put you own authorization key.. 


ChatOpenAI(1).oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.