Skip to content

Commit 2884211

Browse files
authored
Fix issue with API keys (#469)
Propagate xAI and Google API keys all the way to the server. Tested this locally.
1 parent 24cfee6 commit 2884211

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

app/lib/.server/chat.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export async function chatAction({ request }: ActionFunctionArgs) {
5858
teamSlug: string;
5959
deploymentName: string | undefined;
6060
modelProvider: ModelProvider;
61-
userApiKey: { preference: 'always' | 'quotaExhausted'; value?: string; openai?: string } | undefined;
61+
userApiKey:
62+
| { preference: 'always' | 'quotaExhausted'; value?: string; openai?: string; xai?: string; google?: string }
63+
| undefined;
6264
};
6365
const { messages, firstUserMessage, chatId, deploymentName, token, teamSlug } = body;
6466

@@ -100,14 +102,20 @@ export async function chatAction({ request }: ActionFunctionArgs) {
100102
if (body.modelProvider === 'Anthropic' || body.modelProvider === 'Bedrock') {
101103
userApiKey = body.userApiKey?.value;
102104
body.modelProvider = 'Anthropic';
103-
} else {
105+
} else if (body.modelProvider === 'OpenAI') {
104106
userApiKey = body.userApiKey?.openai;
107+
} else if (body.modelProvider === 'XAI') {
108+
userApiKey = body.userApiKey?.xai;
109+
} else {
110+
userApiKey = body.userApiKey?.google;
105111
}
106112
if (!userApiKey) {
107-
const provider = body.modelProvider === 'OpenAI' ? 'OpenAI' : 'Anthropic';
108-
return new Response(JSON.stringify({ error: `Tried to use missing ${provider} API key. Set one in Settings!` }), {
109-
status: 402,
110-
});
113+
return new Response(
114+
JSON.stringify({ error: `Tried to use missing ${body.modelProvider} API key. Set one in Settings!` }),
115+
{
116+
status: 402,
117+
},
118+
);
111119
}
112120
}
113121
logger.info(`Using model provider: ${body.modelProvider} (user API key: ${useUserApiKey})`);

0 commit comments

Comments
 (0)