I get the same result when I run your code. Not that I expected it work, since I assume that you don't post your actual API key in public. But it tells me that with an invalid key, you get NULL back. So that could be the reason.
For deeper troubleshooting, you can set up an extended-evens session with the events external_rest_endpoint_summary and external_rest_endpoint_summary. They include information about the REST call, including http_response_code.
I don't have an OPEN AI account myself, so I cannot test further myself.