1
$\begingroup$

I have tried the canonical example (with the real API Key)

 apiEndpoint = "https://api.openai.com/v1/chat/completions"; apiKey = "myAPIKey1234567"; (*Create the payload for the POST request*) payload = ExportString[<|"model" -> "gpt-4", "messages" -> {<|"role" -> "user", "content" -> "What is the weather in Prague today?"|>} , "max_tokens" -> 50, "temperature" -> 0.7 |>, "JSON" ]; (*Perform the HTTP POST request*) response = URLExecute[ apiEndpoint, {"Method" -> "POST", "Headers" -> {"Content-Type" -> "application/json", "Authorization" -> "Bearer " <> apiKey}, "Body" -> payload}]; 

however the Mathematica 13.2 returned the error message

URLExecute::nvldarg: The argument Content-Type->application/json should be a string

But what is the correct way to send send authentication in the required format?

$\endgroup$
1
  • $\begingroup$ This does not seem to be the way to set headers with URLExecute. Try URLExecute @ HTTPRequest[.... $\endgroup$ Commented Jun 20, 2024 at 9:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.