Thanks everyone for the help. I have solved this specific problem. The solution was to use the json_schema instead of json_object in the API.
So first I used
“response_format”: {
“type”: “json_object”
}
which allowed for the bug to appear sometimes.
And now I used
“response_format”: {
“type”: “json_schema”,
“json_schema”: my_json_schema
}
where I never encounter the bug anymore.