Google AI Studio Adds ‘Import from GitHub’ to Build Mode, Turning an Existing Repo Into an Editable, Deployable App

0


// Discouraged: calling the Gemini API from the browser exposes the key
const res = await fetch(
“https://generativelanguage.googleapis.com/v1beta/models/gemini-flash-latest:generateContent”,
{
method: “POST”,
headers: {
“Content-Type”: “application/json”,
“x-goog-api-key”: MY_KEY, // visible in the client bundle
},
body: JSON.stringify({ contents: [{ parts: [{ text: “Hello” }] }] }),
}
);

// Recommended: read the key from the server environment, call the API server-side
// GEMINI_API_KEY lives in the server-side runtime, not in shipped client code.
export async function handler(req) {
const apiKey = process.env.GEMINI_API_KEY; // server-side only
const r = await fetch(
“https://generativelanguage.googleapis.com/v1beta/models/gemini-flash-latest:generateContent”,
{
method: “POST”,
headers: {
“Content-Type”: “application/json”,
“x-goog-api-key”: apiKey,
},
body: JSON.stringify({ contents: [{ parts: [{ text: “Hello” }] }] }),
}
);
return new Response(await r.text(), { status: r.status });
}



Source link

You might also like
Leave A Reply

Your email address will not be published.