Skip to content

Commit e534c3d

Browse files
SSK-14saoudrizwan
andauthored
Add api key for litellm api provider RooCodeInc#1766 (RooCodeInc#1767)
* Add api key for litellm api provider * Added Changeset * Update litellm.ts * Update ApiOptions.tsx --------- Co-authored-by: Saoud Rizwan <[email protected]>
1 parent add2f85 commit e534c3d

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

.changeset/slimy-toes-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": minor
3+
---
4+
5+
Added api key field for litellm api provider in settings

src/api/providers/litellm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class LiteLlmHandler implements ApiHandler {
1313
this.options = options
1414
this.client = new OpenAI({
1515
baseURL: this.options.liteLlmBaseUrl || "http://localhost:4000",
16-
apiKey: "not-needed",
16+
apiKey: this.options.liteLlmApiKey || "noop",
1717
})
1818
}
1919

src/core/webview/ClineProvider.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type SecretKey =
4949
| "togetherApiKey"
5050
| "qwenApiKey"
5151
| "mistralApiKey"
52+
| "liteLlmApiKey"
5253
| "authToken"
5354
| "authNonce"
5455
type GlobalStateKey =
@@ -334,15 +335,15 @@ export class ClineProvider implements vscode.WebviewViewProvider {
334335

335336
// Use a nonce to only allow a specific script to be run.
336337
/*
337-
content security policy of your webview to only allow scripts that have a specific nonce
338-
create a content security policy meta tag so that only loading scripts with a nonce is allowed
339-
As your extension grows you will likely want to add custom styles, fonts, and/or images to your webview. If you do, you will need to update the content security policy meta tag to explicity allow for these resources. E.g.
340-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${webview.cspSource}; font-src ${webview.cspSource}; img-src ${webview.cspSource} https:; script-src 'nonce-${nonce}';">
338+
content security policy of your webview to only allow scripts that have a specific nonce
339+
create a content security policy meta tag so that only loading scripts with a nonce is allowed
340+
As your extension grows you will likely want to add custom styles, fonts, and/or images to your webview. If you do, you will need to update the content security policy meta tag to explicity allow for these resources. E.g.
341+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${webview.cspSource}; font-src ${webview.cspSource}; img-src ${webview.cspSource} https:; script-src 'nonce-${nonce}';">
341342
- 'unsafe-inline' is required for styles due to vscode-webview-toolkit's dynamic style injection
342343
- since we pass base64 images to the webview, we need to specify img-src ${webview.cspSource} data:;
343344
344-
in meta tag we add nonce attribute: A cryptographic nonce (only used once) to allow scripts. The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.
345-
*/
345+
in meta tag we add nonce attribute: A cryptographic nonce (only used once) to allow scripts. The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.
346+
*/
346347
const nonce = getNonce()
347348

348349
// Tip: Install the es6-string-html VS Code extension to enable code highlighting below
@@ -462,6 +463,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
462463
vsCodeLmModelSelector,
463464
liteLlmBaseUrl,
464465
liteLlmModelId,
466+
liteLlmApiKey,
465467
qwenApiLine,
466468
} = message.apiConfiguration
467469
await this.updateGlobalState("apiProvider", apiProvider)
@@ -492,6 +494,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
492494
await this.storeSecret("togetherApiKey", togetherApiKey)
493495
await this.storeSecret("qwenApiKey", qwenApiKey)
494496
await this.storeSecret("mistralApiKey", mistralApiKey)
497+
await this.storeSecret("liteLlmApiKey", liteLlmApiKey)
495498
await this.updateGlobalState("azureApiVersion", azureApiVersion)
496499
await this.updateGlobalState("openRouterModelId", openRouterModelId)
497500
await this.updateGlobalState("openRouterModelInfo", openRouterModelInfo)
@@ -1416,6 +1419,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
14161419
previousModeModelId,
14171420
previousModeModelInfo,
14181421
qwenApiLine,
1422+
liteLlmApiKey,
14191423
] = await Promise.all([
14201424
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
14211425
this.getGlobalState("apiModelId") as Promise<string | undefined>,
@@ -1465,6 +1469,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
14651469
this.getGlobalState("previousModeModelId") as Promise<string | undefined>,
14661470
this.getGlobalState("previousModeModelInfo") as Promise<ModelInfo | undefined>,
14671471
this.getGlobalState("qwenApiLine") as Promise<string | undefined>,
1472+
this.getSecret("liteLlmApiKey") as Promise<string | undefined>,
14681473
])
14691474

14701475
let apiProvider: ApiProvider
@@ -1525,6 +1530,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
15251530
o3MiniReasoningEffort,
15261531
liteLlmBaseUrl,
15271532
liteLlmModelId,
1533+
liteLlmApiKey,
15281534
},
15291535
lastShownAnnouncementId,
15301536
customInstructions,
@@ -1617,6 +1623,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
16171623
"togetherApiKey",
16181624
"qwenApiKey",
16191625
"mistralApiKey",
1626+
"liteLlmApiKey",
16201627
"authToken",
16211628
]
16221629
for (const key of secretKeys) {

src/shared/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ApiHandlerOptions {
2121
apiKey?: string // anthropic
2222
liteLlmBaseUrl?: string
2323
liteLlmModelId?: string
24+
liteLlmApiKey?: string
2425
anthropicBaseUrl?: string
2526
openRouterApiKey?: string
2627
openRouterModelId?: string

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,14 @@ const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage, is
900900

901901
{selectedProvider === "litellm" && (
902902
<div>
903+
<VSCodeTextField
904+
value={apiConfiguration?.liteLlmApiKey || ""}
905+
style={{ width: "100%" }}
906+
type="password"
907+
onInput={handleInputChange("liteLlmApiKey")}
908+
placeholder="Default: noop">
909+
<span style={{ fontWeight: 500 }}>API Key</span>
910+
</VSCodeTextField>
903911
<VSCodeTextField
904912
value={apiConfiguration?.liteLlmBaseUrl || ""}
905913
style={{ width: "100%" }}

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const ExtensionStateContextProvider: React.FC<{
6565
config.openAiApiKey,
6666
config.ollamaModelId,
6767
config.lmStudioModelId,
68+
config.liteLlmApiKey,
6869
config.geminiApiKey,
6970
config.openAiNativeApiKey,
7071
config.deepSeekApiKey,

0 commit comments

Comments
 (0)