You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const { messages } = await req.json();
console.log("Received messages:", messages);
// const genAI = new GoogleGenerativeAI(apiKey);
const geminiStream = await genAI
.getGenerativeModel({ model: 'gemini-pro' })
.generateContentStream(buildGoogleGenAIPrompt(messages));
console.log("Generated Gemini stream:", geminiStream);
// Convert the response into a friendly text-stream
const stream = GoogleGenerativeAIStream(geminiStream);
console.log("Converted stream:", stream);
return new StreamingTextResponse(stream);
} catch (error) {
console.error("Internal server error:", error);
return new Response("Internal server error", { status: 500 });
}
}
this is my post request function , and i am getting the following error Internal server error: Error: [403 Forbidden] Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API. So to remove this error i have to pass the API key assigned to a query parameter named key. how to do that ,
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
import { GoogleGenerativeAI } from '@google/generative-ai';
import { GoogleGenerativeAIStream, Message, StreamingTextResponse } from 'ai';
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
export const runtime = 'edge';
const buildGoogleGenAIPrompt = (messages: Message[]) => ({
contents: messages
.filter(message => message.role === 'user' || message.role === 'assistant')
.map(message => ({
role: message.role === 'user' ? 'user' : 'model',
parts: [{ text: message.content }],
})),
});
export async function POST(req: Request,res:Response) {
try {
} catch (error) {
console.error("Internal server error:", error);
return new Response("Internal server error", { status: 500 });
}
}
this is my post request function , and i am getting the following error Internal server error: Error: [403 Forbidden] Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API. So to remove this error i have to pass the API key assigned to a query parameter named key. how to do that ,
Beta Was this translation helpful? Give feedback.
All reactions