Response and response in network tab are different

the response and response in network tab are different
when im making api request to chat-completions,
in the logging i get:

body: (...)
bodyUsed: false
headers: Headers {}
ok: false
redirected: false
status: 400
statusText: ""
type: "cors"
url: "https://api.openai.com/v1/chat/completions"

while in the network tab the response is:

{
  "error": {
    "message": "This model's maximum context length is 8192 tokens. However, your messages resulted in 8289 tokens. Please reduce the length of the messages.",
    "type": "invalid_request_error",
    "param": "messages",
    "code": "context_length_exceeded"
  }
}

how can i get the error response as the network?

You’ll need to count your tokens before you send to make sure you don’t go over, or query then handle the error object…

okay I found the issue and it is possible,
the issue was that I tried to access the response before json() it.
then I managed to get the error object by accessing the data from the response.json( )

1 Like