i am getiing this error:
Error: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [400 ] API key not valid. Please pass a valid API key.
here is gemini-ai.ts code:
import { GoogleGenerativeAI } from "@google/generative-ai"; const apiKey = process.env.GEMINI_API_KEY as string ; const genAI = new GoogleGenerativeAI(apiKey); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash", }); const generationConfig = { temperature: 1, topP: 0.95, topK: 64, maxOutputTokens: 8192, responseMimeType: "text/plain", }; export const chatSession = model.startChat({ generationConfig: generationConfig, history: [], }); .
i think problem is related to environment variable.
New contributor
Bharat Kasera is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.