import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';

async function main() {
  const customClient = createOpenAI({
    baseURL: 'https://openrouter.ai/api/v1/',
    apiKey: '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', // If we don't have it, we use a fake or look it up
    compatibility: 'compatible',
  });

  const model = customClient('google/gemma-4-26b-a4b-it');

  try {
    const { text } = await generateText({
      model: model,
      system: "Tu es l'Assistant IA",
      messages: [
        { role: 'user', content: 'hello ...' },
        { role: 'assistant', content: 'La configuration...' },
        { role: 'user', content: 'dis moi comment utilis...' }
      ],
    });
    console.log("SUCCESS:", text);
  } catch (err: any) {
    console.error("FAILURE:", err.message);
    if (err.cause) console.error("CAUSE:", err.cause);
    if (err.data) console.error("DATA:", err.data);
  }
}

main().catch(console.error);
