Hi all,
I create a thread, then successfully add and retrieve messages to it using https://api.openai.com/v1/threads/thread_id/messages, but when I try to create a run using https://api.openai.com/v1/threads/thread_id/runs - with exactly the same thread_id and other parameters, I am getting 404 error with the description “No thread found with id ‘thread_id’”
Anyone have an idea what the problem is?
If that matters, I’m using curl from PHP code…
thanks in advance
Add your code here. Let’s see what the problem is.
The code is below. The variables such as apiKey, assistanceId are properly set (I dump the entire POST request in PHP lig file to check). The threadId is absolutely the same as I set when calling (successfully) https://api.openai.com/v1/threads//messages
—code:—
$url = “https://api.openai.com/v1/threads/$threadId/runs”;
$headers = [
“Content-Type: application/json”,
“Authorization: Bearer $apiKey”,
“OpenAI-Beta: assistants=v2”,
‘OpenAI-Organization: org-###’,
‘OpenAI-Project: proj_###’
];
$postData = json_encode([
‘assistant_id’ => $assistantId
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
If it helps, the examples of responses I get:
calling /threards:
{
“id”: “thread_OMwBnHIPI1bAGS07hOD3Cskp”,
“object”: “thread”,
“created_at”: 1717338767,
“metadata”: {},
“tool_resources”: {}
}
calling /messages:
{
“object”: “list”,
“data”: [
{
“id”: “msg_aGLjiak1Uc9tIK1cxqmasZez”,
“object”: “thread.message”,
“created_at”: 1717338779,
“assistant_id”: null,
“thread_id”: “thread_OMwBnHIPI1bAGS07hOD3Cskp”,
“run_id”: null,
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: {
“value”: “A TEST MESSAGE”,
“annotations”:
}
}
],
“attachments”: ,
“metadata”: {}
}
],
“first_id”: “msg_aGLjiak1Uc9tIK1cxqmasZez”,
“last_id”: “msg_aGLjiak1Uc9tIK1cxqmasZez”,
“has_more”: false
}
calling /runs:
{“error”: {“message”: “No thread found with id ‘thread_OMwBnHIPI1bAGS07hOD3Cskp’.”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
Solved but weird. I generated a new API KEY and the app started working with it.
Totally weird, as the old key was active, and I had another app (using completion API) that kept working with that old key.
Also, why OpenAI gives “thread not found” error if it actually does not like the key? :):)
I wonder if a key can all of a sudden stop working when the app is in production runtime…
2 Likes
I just generate a new API_KEY and add to the header and the problem solved.
Your, solution worked brother. Thank you!
I had the same issue in a production service. For me, it was quite isolated and rare; it appeared to be a systematic error from OpenAI where the “thread_id” was lost. I would recommend implementing retries in your assistant flows for your application.