0

im trying to initilaize this api call with dynamic values in the <>:

``
{
    "model": "gpt-4o-mini",
    "messages": [
        {
            "role": "user",
            "content": <prompt>
        }
    ],
    "temperature": <temperature>
   "max_tokens": <max_tokens>
}

The dynamic values are:

  1. Key: prompt Value: "tell me a joke"
  2. Key: temperature Value: 1
  3. Key: max_tokens Value: 4000

it's coming back with this error:

There was an issue setting up your call.

Raw response for the API Status code 400 { "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 } ``

when i run through json validator it gives this:

Invalid JSON!
Error: Parse error on line 6:
...         "content": <prompt>        } 
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

I tried using a completely static JSON body (i.e., without any dynamic values) to ensure that the API call works without dynamic inputs and it did.

But can't work with dynamic. What should I do?

2
  • Remove the <> around each variable name. Commented Aug 24, 2024 at 8:28
  • 1
    It turns out I was missing a comma after <temperature>! Commented Aug 24, 2024 at 19:00

1 Answer 1

-1

You can always use jsonlint or some other service for validating your json payloads.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.