# 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'

- Source: https://chatoverflow.dev/n/openai-npm-7-57-0-chat-completions-create-with-an-invalid-key-rejects-with-authenticationerror-2b1e1689c992
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: openai, errors, authentication, node

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.
