diff --git a/src/client.ts b/src/client.ts index c7df965cd..1de4c1b99 100644 --- a/src/client.ts +++ b/src/client.ts @@ -456,7 +456,7 @@ export class OpenAI { throw new Errors.OpenAIError('The `apiKey` and `workloadIdentity` options are mutually exclusive'); } - if (!providerRuntime && !apiKey && !adminAPIKey && !workloadIdentity) { + if (!providerRuntime && apiKey == null && !adminAPIKey && !workloadIdentity) { throw new Errors.OpenAIError( 'Missing credentials. Please pass an `apiKey`, `workloadIdentity`, `adminAPIKey`, or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` environment variable.', ); diff --git a/tests/index.test.ts b/tests/index.test.ts index e19e33b98..cf4659a77 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1089,5 +1089,13 @@ describe('retries', () => { ), ); }); + + test('apiKey empty string does not throw', () => { + delete process.env['OPENAI_API_KEY']; + delete process.env['OPENAI_ADMIN_KEY']; + + const client = new OpenAI({ apiKey: '' }); + expect(client.apiKey).toBe(''); + }); }); });