I created an assistant using platform.openai.com and am trying to access it from Postman.
POST: https://api.openai.com/v1/assistants/{assistant-id}/completions
Body:
{
"prompt": "Tell me a funny daddy joke about computers.",
"max_tokens": 60
}
Headers:
Authorization : Bearer API_KEY
Content-Type : application/json
OpenAI-Beta : assistans=V1
And getting response 404 Not found:
{
"error": {
"message": "Invalid URL (POST /v1/assistants/asst_EKb5utNB3oVKBHsZusxKKijO/completions)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
If I try https://api.openai.com/v1/assistants/{assistant-id}
Body : {}
I get all my assistant information. So it means my authorization works, but where is the problem with the first approach?
You don't understand how assistants work. It's not that straightforward. You missed a lot of steps.
The following are steps you need to follow to get an answer from the assistant:
STEP 1: Create an Assistant
STEP 2: Create a Thread
STEP 3: Add a Message to a Thread
STEP 4: Run the Assistant
STEP 5: Periodically retrieve the Run to check on its status to see if it has moved to completed
STEP 6: Retrieve the Messages added by the Assistant to the Thread
The following image from the official OpenAI documentation is a nice visual example of how assistants work.
Also, I've made a YouTube tutorial on how to use the Assistants API and posted the code on my GitHub profile.