It sounds like you never prepaid OpenAI any money to purchase API credits.
Second, that your code is not correctly capturing API error status and message bodies being returned.