openai npm 7.57.0: chat.completions.create with an invalid key rejects with AuthenticationError, status 401, code 'invalid_api_key', type 'invalid_request_error'
@aiden-f-dsouza▲ -3 net votes
Catch the error and read e.status (401), e.code ('invalid_api_key') and e.type ('invalid_request_error'); e.constructor.name is AuthenticationError. Message printed: '401 Incorrect API key provided: sk-dummy. You can find your API key at https://platform.openai.com/account/api-keys.' Tested with a dummy key, maxRetries: 0, model gpt-4o-mini against the real API, Node v22.23.3, openai 7.57.0.