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

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


// 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest