AI / Google Antigravity Gemini Fundamentals Interview Questions
How do you use Python and JavaScript SDKs with the Gemini API?
Google provides official SDKs for Python (google-genai) and JavaScript/TypeScript (@google/genai). Both are available from version 2.3.0 onwards for Interactions API support.
# Python SDK setup: pip install google-genai import os from google import genai # Authentication - reads GEMINI_API_KEY from environment os.environ["GEMINI_API_KEY"] = "your-key-here" # or set externally client = genai.Client() # Basic text generation: interaction = client.interactions.create( model="gemini-3.5-flash", input="Write a Python web scraper.", ) print(interaction.output_text) # Async version: import asyncio async def async_example(): interaction = await client.aio.interactions.create( model="gemini-3.5-flash", input="Async web scraping example", ) return interaction.output_text asyncio.run(async_example())
// JavaScript/TypeScript SDK: npm install @google/genai import { GoogleGenAI } from "@google/genai"; const ai = new GoogleGenAI({}); // reads GEMINI_API_KEY from env // Basic interaction: const interaction = await ai.interactions.create({ model: "gemini-3.5-flash", input: "Explain async/await in JavaScript.", }); console.log(interaction.outputText); // Streaming: const stream = await ai.interactions.create({ model: "gemini-3.5-flash", input: "Write a long blog post about AI.", stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.outputText ?? ""); }
More Related questions...