@@ -61,45 +61,64 @@ export class ApiKeySettingsHelper {
6161 */
6262 async getUserApiKeysConfig ( ) : Promise < IUserApiKeyConfig | undefined > {
6363 try {
64- // First check if user has permission to use own API keys
64+ // Whether the user may swap the Remix proxy for their own keys on the
65+ // proxy-backed providers (anthropic / mistral / openai / moonshot).
6566 const hasPermission = await this . canUseOwnApiKeys ( )
66- if ( ! hasPermission ) {
67- remixAILogger . log ( '[ApiKeySettingsHelper] User does not have permission to use own API keys' )
68- return undefined
69- }
7067
71- // Read settings via plugin calls (parallel for performance)
72- const [ useOwnKeysValue , anthropicApiKey , mistralApiKey , openaiApiKey , moonshotApiKey ] = await Promise . all ( [
68+ // Read settings via plugin calls (parallel for performance). We read the
69+ // Bedrock API key regardless of `hasPermission`, because Bedrock has no
70+ // Remix proxy: if the user entered a key it must be used, there's no
71+ // proxy alternative to gate it against. The permission flag only governs
72+ // the proxy-backed providers below.
73+ const [
74+ useOwnKeysValue ,
75+ anthropicApiKey ,
76+ mistralApiKey ,
77+ openaiApiKey ,
78+ moonshotApiKey ,
79+ bedrockBearerToken
80+ ] = await Promise . all ( [
7381 this . getSetting ( 'deepagent-api-keys-config' ) ,
7482 this . getSetting ( 'deepagent-anthropic-api-key' ) ,
7583 this . getSetting ( 'deepagent-mistral-api-key' ) ,
7684 this . getSetting ( 'deepagent-openai-api-key' ) ,
77- this . getSetting ( 'deepagent-moonshot-api-key' )
85+ this . getSetting ( 'deepagent-moonshot-api-key' ) ,
86+ this . getSetting ( 'deepagent-bedrock-bearer-token' )
7887 ] )
7988
8089 const useOwnKeys = useOwnKeysValue === 'true' || useOwnKeysValue === true
8190
91+ const hasBedrockKey = ! ! bedrockBearerToken
92+
93+ // Proxy-provider own keys are gated behind the permission; the Bedrock
94+ // key is not (see above).
95+ const anthropic = hasPermission ? String ( anthropicApiKey || '' ) : ''
96+ const mistral = hasPermission ? String ( mistralApiKey || '' ) : ''
97+ const openai = hasPermission ? String ( openaiApiKey || '' ) : ''
98+ const moonshot = hasPermission ? String ( moonshotApiKey || '' ) : ''
99+ const hasAnyProxyKey = ! ! ( anthropic || mistral || openai || moonshot )
100+
82101 // Debug logging
83102 remixAILogger . log ( '[ApiKeySettingsHelper] Reading API keys from settings:' , {
103+ hasPermission,
84104 useOwnKeys,
85- hasAnthropicKey : ! ! anthropicApiKey ,
86- hasMistralKey : ! ! mistralApiKey ,
87- hasOpenaiKey : ! ! openaiApiKey ,
88- hasMoonshotKey : ! ! moonshotApiKey
105+ hasAnyProxyKey,
106+ hasBedrockKey
89107 } )
90108
91- // Auto-enable if any API key is set
92- const hasAnyKey = anthropicApiKey || mistralApiKey || openaiApiKey || moonshotApiKey
93- if ( ! useOwnKeys && ! hasAnyKey ) {
109+ // Nothing to contribute → callers fall back to the proxy.
110+ // - No Bedrock key AND no proxy-provider own keys in play.
111+ if ( ! hasBedrockKey && ! hasAnyProxyKey && ! ( useOwnKeys && hasPermission ) ) {
94112 return undefined
95113 }
96114
97115 return {
98- useOwnKeys : useOwnKeys || ! ! hasAnyKey ,
99- anthropicApiKey : String ( anthropicApiKey || '' ) ,
100- mistralApiKey : String ( mistralApiKey || '' ) ,
101- openaiApiKey : String ( openaiApiKey || '' ) ,
102- moonshotApiKey : String ( moonshotApiKey || '' )
116+ useOwnKeys : ( useOwnKeys && hasPermission ) || hasAnyProxyKey || hasBedrockKey ,
117+ anthropicApiKey : anthropic ,
118+ mistralApiKey : mistral ,
119+ openaiApiKey : openai ,
120+ moonshotApiKey : moonshot ,
121+ bedrockBearerToken : String ( bedrockBearerToken || '' )
103122 }
104123 } catch ( error ) {
105124 remixAILogger . warn ( '[ApiKeySettingsHelper] Failed to read user API keys config:' , error )
@@ -112,6 +131,12 @@ export class ApiKeySettingsHelper {
112131 */
113132 async isUsingOwnApiKeyForProvider ( provider : string ) : Promise < boolean > {
114133 try {
134+ // Bedrock has no proxy — it's always "own key" when a Bedrock API key is
135+ // present, independent of the proxy-vs-own-key toggle.
136+ if ( provider === 'bedrock' ) {
137+ return ! ! ( await this . getSetting ( 'deepagent-bedrock-bearer-token' ) )
138+ }
139+
115140 const useOwnKeysValue = await this . getSetting ( 'deepagent-api-keys-config' )
116141 const useOwnKeys = useOwnKeysValue === 'true' || useOwnKeysValue === true
117142
0 commit comments