I’m currently building a school project and we’re using ChatGPT API inside to have more customization.
This is my current code to setup the request:
let url = URL(string: "https://api.openai.com/v1/assistants/(assistant_id)/chat/completions")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("Bearer (String(describing: self.apiKey!))", forHTTPHeaderField: "Authorization")
request.addValue("assistants=v2", forHTTPHeaderField: "OpenAI-Beta")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: Any] = [
"model": "gpt-4-turbo",
"messages": [
["role": "user", "content": prompt]
]
]
But I only get this response from the API:
Invalid URL (POST /v1/assistants/MY_ASSIST_ID/chat/completions)
(where MY_ASSIST_ID is my assistant ID)
I think the URL is wrong as it says but I can’t find the right URL.
Can someone help me and explain what’s wrong please?