Curl: could not parse the JSON body of your request

Hello forum,

I´m a newbie and have a first look on the api. I want to use curl in a windows command prompt. I copied the code from the first example:

curl …chat/completions -H “Content-Type: application/json” -H “Authorization: Bearer MyKey” -d ‘{“model”: “gpt-4o”, “messages”: [ { “role”: “system”, “content”: “You are a helpful assistant.” } ] }’

The word “myKey” is replaced with my real key.

The syntax seems to be ok, for i only copied the text.

But I got the following errormessage:

"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 contact us through our help center at help.openai.com.)",
        "type": "invalid_request_error",
        "param": null,
        "code": null

Where is my mistake?

Many thanks for your help.

Welcome forumite,

Windows cmd is a bit special, you need to escape your json quotes with \"

ChatGPT is often your friend here :^)

Ignore that it says powershell, it’s cmd.

2 Likes

Thanks a lot for yout help? :grinning:

1 Like

not sure if it’s an artifact of the forum or the exampl, but the curly " used may be the issue, also you only have a system prompt, I;ve added a user one, try

curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer MY_KEY" -d "{\"model\": \"gpt-4\", \"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}, {\"role\": \"user\", \"content\": \"What is the capital of France?\"}]}"

2 Likes