ravise
1
Hi,
I am trying to use the below in the Request body while calling the OpenAI API via the Invoke web service of the Power Automate Desktop RPA tool.
{
“model”:“text-davinci-003”,
“prompt”:“What is the capital of India?”,
“temperature”:0,
“max_tokens”:100,
“top_p”:1,
“frequency_penalty”:0.0,
“presence_penalty”:0.0
}
However, after several modifications I am unable to determine what is the wrong in the above Request as I am constantly getting the below error.
{
“error”: {
“message”: “We could not parse the JSON body of your request. (HINT: This likely means you aren’t using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to support@openai.com and include any relevant code you’d like help with.)”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
URL- https://api.openai.com/v1/engines/davinci/completions
Post method
Content type- application/json
Please advise of anything wrong in the above.
Thanks.
1 Like
Dent
2
Welcome to the forum!
This may be nothing, but the URL you posted points to a deprecated endpoint. You might try ths documentation: https://beta.openai.com/docs/api-reference/completions/create?lang=curl
Hope that helps!
3 Likes
In my experience, I had to ensure the object was jsonified, and THAT string was encoded as UTF-8
System.Text.Encoding.UTF8.GetBytes(dataAsJSON);
1 Like
ravise
4
Hi @Dent ,
Thank you very much for pointing me to the right URL.
The new URL I am using is https://api.openai.com/v1/completions
and the Request is
{
“model”: “text-davinci-003”,
“prompt”: “Say this is a test”,
“max_tokens”: 7,
“temperature”: 0,
“top_p”: 1,
“n”: 1,
“stream”: false,
“logprobs”: null,
“stop”: “\n”
}
However I am seeing the same error as below.
What else could be different?
{
“error”: {
“message”: “We could not parse the JSON body of your request. (HINT: This likely means you aren’t using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to support@openai.com and include any relevant code you’d like help with.)”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
ravise
5
Hi @SomeUser2022
Could you please clarify what you meant by “object was jsonified”?
The request I am passing is already a json format.
Tried Content type with and without utf-8 (application/json; charset=utf-8)
{
“model”: “text-davinci-003”,
“prompt”: “Say this is a test”,
“max_tokens”: 7,
“temperature”: 0,
“top_p”: 1,
“n”: 1,
“stream”: false,
“logprobs”: null,
“stop”: “\n”
}
ravise
6
Hi @Dent , @SomeUser2022
Thank you for your responses.
Finally I have received the output.
After the change in URL suggested by @Dent I had to disable the attached “URL encoding” option which was enabled by default.
Feels like an achievement 
1 Like
Dent
7
That’s great! And thank you for posting your solution, and not being another DenverCoder9!

source
2 Likes
ravise
8
. Welcome. Looks like there is no “mark as solution” option here.
1 Like
Edited title as [SOLVED]…
Feel free to start a new thread if you run into any problems… or eventually want to share what you’re building!
@ravise
Dear Ravise, where do you disable the encode request body option?
pulti
12
Can you please guide me where i have to disable this option as i am getting same error through power-automate using web. @Dent can you please help here how can i disable URL encoding for cloud flows?
ravise
13
Hi @andresfelipe180890, @pulti
It is in the Advanced section of Invoke web services action.
Please note that my post is related to Power Automate Desktop and not Cloud flows.
pulti
14
I am using cloud Flows and wanted to know how can i disable this using cloud flow HTTP method
I have this same error it works with short prompts but I am trying to feed it a bunch of text from a document for it to summarize. The text has alll sorts of things like numbers etc and just comes from a text file. I keep getting this error though. Is there a certain format the text needs to be in?
ravise
16
Hi @patsupanich,
If its working fine with a smaller text, but giving error with a larger text then try increasing the token size in the parameter.
Secondly, I have observed that I used to get errors when there was a double quotation mark in the input text. When I removed them it worked fine. So check for those also.
Thanks.
hi all,
i have applied all the above mentioned possible solutions, but still i am getting the same error response.
The following is the input that I am passing to the API request:
It is giving the following response when I pass large input text.
{
“error”: {
“message”: “We could not parse the JSON body of your request. (HINT: This likely means you aren’t using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to support@openai.com and include any relevant code you’d like help with.)”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
For small input texts I am getting the correct response.
Please help me to resolve this.
Thanks
the following is the input API request
Hi, I am also facing a similar problem and don’t know what to do. Tried the suggestions above but not working. Here is the sample of the code:
Error:
{
"detail": "Failed to get OpenAI API token: {\n \"error\": {\n \"message\": \"We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)\",\n \"type\": \"invalid_request_error\",\n \"param\": null,\n \"code\": null\n }\n}\n"
}