feat: suporte para provedor OpenRouter

This commit is contained in:
2026-06-22 20:06:40 +00:00
parent f41c5eccd2
commit ba10367855
4 changed files with 95 additions and 4 deletions
+28
View File
@@ -26,6 +26,8 @@ export const testApiKey = async (provider: AIProvider, apiKey: string, endpoint?
return await testAzure(apiKey, endpoint);
case 'ollama':
return await testOllama(endpoint);
case 'openrouter':
return await testOpenRouter(apiKey);
default:
return { success: false, error: 'Provedor não suportado' };
}
@@ -229,4 +231,30 @@ const testAzure = async (apiKey: string, endpoint: string): Promise<TestResult>
} catch (error: any) {
return { success: false, error: error.message || 'Erro ao conectar com Azure' };
}
};
const testOpenRouter = async (apiKey: string): Promise<TestResult> => {
try {
const response = await fetch('https://openrouter.ai/api/v1/models', {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
if (!response.ok) {
const error = await response.json();
return { success: false, error: error.error?.message || 'Chave de API inválida' };
}
return {
success: true,
models: [
{ id: 'google/gemini-2.5-flash', name: 'Gemini 2.5 Flash' },
{ id: 'google/gemini-2.5-pro', name: 'Gemini 2.5 Pro' },
{ id: 'anthropic/claude-3.5-sonnet', name: 'Claude 3.5 Sonnet' },
{ id: 'openai/gpt-4o', name: 'GPT-4o' },
{ id: 'meta-llama/llama-3.1-70b-instruct', name: 'Llama 3.1 70B' }
]
};
} catch (error: any) {
return { success: false, error: error.message || 'Erro ao conectar com OpenRouter' };
}
};