Fix provider API key validation trimming (#810)

This commit is contained in:
Lingxuan Zuo
2026-04-10 15:15:29 +08:00
committed by GitHub
parent 66b2ddb2dc
commit 49518300dc
7 changed files with 155 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ import type {
ProviderVendorInfo,
ProviderWithKeyInfo,
} from '@/lib/providers';
import { normalizeProviderApiKeyInput } from '@/lib/providers';
import { hostApiFetch } from '@/lib/host-api';
import {
fetchProviderSnapshot,
@@ -326,9 +327,10 @@ export const useProviderStore = create<ProviderState>((set, get) => ({
validateAccountApiKey: async (providerId, apiKey, options) => {
try {
const normalizedApiKey = normalizeProviderApiKeyInput(apiKey);
const result = await hostApiFetch<{ valid: boolean; error?: string }>('/api/providers/validate', {
method: 'POST',
body: JSON.stringify({ providerId, apiKey, options }),
body: JSON.stringify({ providerId, apiKey: normalizedApiKey, options }),
});
return result;
} catch (error) {