Skip to content

Commit d965d96

Browse files
authored
Fix API key not persisting (#549)
1 parent 419cdda commit d965d96

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/extension/byok/vscode-node/anthropicProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class AnthropicLMProvider implements BYOKModelProvider<LanguageModelChatI
5353
async updateAPIKey(): Promise<void> {
5454
this._apiKey = await promptForAPIKey(AnthropicLMProvider.providerName, await this._byokStorageService.getAPIKey(AnthropicLMProvider.providerName) !== undefined);
5555
if (this._apiKey) {
56-
this._byokStorageService.storeAPIKey(AnthropicLMProvider.providerName, this._apiKey, BYOKAuthType.GlobalApiKey);
56+
await this._byokStorageService.storeAPIKey(AnthropicLMProvider.providerName, this._apiKey, BYOKAuthType.GlobalApiKey);
5757
}
5858
}
5959

src/extension/byok/vscode-node/baseOpenAICompatibleProvider.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { IInstantiationService } from '../../../util/vs/platform/instantiation/c
1111
import { CopilotLanguageModelWrapper } from '../../conversation/vscode-node/languageModelAccess';
1212
import { BYOKAuthType, BYOKKnownModels, byokKnownModelsToAPIInfo, BYOKModelCapabilities, BYOKModelProvider, resolveModelInfo } from '../common/byokProvider';
1313
import { OpenAIEndpoint } from '../node/openAIEndpoint';
14+
import { OpenAIResponsesEndpoint } from '../node/openAIResponsesEndpoint';
1415
import { IBYOKStorageService } from './byokStorageService';
1516
import { promptForAPIKey } from './byokUIService';
16-
import { OpenAIResponsesEndpoint } from '../node/openAIResponsesEndpoint';
1717

1818
export abstract class BaseOpenAICompatibleLMProvider implements BYOKModelProvider<LanguageModelChatInformation> {
1919

@@ -107,9 +107,14 @@ export abstract class BaseOpenAICompatibleLMProvider implements BYOKModelProvide
107107
return;
108108
}
109109
const newAPIKey = await promptForAPIKey(this._name, await this._byokStorageService.getAPIKey(this._name) !== undefined);
110-
if (newAPIKey) {
110+
if (newAPIKey === undefined) {
111+
return;
112+
} else if (newAPIKey === '') {
113+
this._apiKey = undefined;
114+
await this._byokStorageService.deleteAPIKey(this._name, this.authType);
115+
} else if (newAPIKey !== undefined) {
111116
this._apiKey = newAPIKey;
112-
this._byokStorageService.storeAPIKey(this._name, this._apiKey, BYOKAuthType.GlobalApiKey);
117+
await this._byokStorageService.storeAPIKey(this._name, this._apiKey, BYOKAuthType.GlobalApiKey);
113118
}
114119
}
115120
}

0 commit comments

Comments
 (0)