Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
Expand Down
8 changes: 8 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
});
});