Hey I'm getting error code 400 when trying to use an Arduino to send a web request to ChatGPT
Here's the code ```cpp
include <WiFi.h>
char * ssid = "";
char * password = "";
char * key = "Bearer xxxxx"; //deleted all the info for ssid, pass & key because privacy -- pretend it's filled in
void setup() {
Serial.begin(9600);
if (!Serial) { delay(5000); }
Serial.print("Connecting to WiFi\n");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { continue; }
Serial.print("Connected!\n");
WiFiSSLClient client;
Serial.print("Connecting to OpenAI\n");
if (!client.connectSSL("api.openai.com", 443)) {
Serial.print("Connection failed!");
return;
}
Serial.print("Connected!\n");
String payload = "{
"model": "gpt-3.5-turbo",
"messages": [{
"role": "user",
"content": "Why is grass green?"
}]
}";
client.println("POST /v1/chat/completions HTTPS/1.0");
client.println("Host: api.openai.com");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(payload.length());
client.print("Authorization: ");
client.println(key);
client.println();//separate data from headers
client.println(payload);
while (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.print("disconnected\n");
client.stop();
}
}
void loop() {
}
this is the error code (pic related)
And here's the web request working as intended (pic related) so I know my overall request is okay, just the formatting or something with Arduino is what's wrong