Developing with the Gemini API
Use the maintained Google Gen AI SDK and an available model identifier. Old examples using Gemini 1.0 or 1.5 and the legacy Python package should not be treated as a current model catalog.
#Prepare a server-side client
bashpython -m pip install google-genai
Set GEMINI_API_KEY and GEMINI_MODEL in the server environment. Keep the key out of frontend bundles, repository files and logs. Account eligibility, quotas and billing terms vary; do not assume every request is free.
The following Python example uses the SDK's Interactions interface shown in the current getting-started guide. It requires a compatible SDK release and an authorized account. Running it sends a provider request and may incur charges.
pythonimport os from google import genai client = genai.Client(api_key=os.environ["GEMINI_API_KEY"]) interaction = client.interactions.create( model=os.environ["GEMINI_MODEL"], input="Explain a Python iterator in two sentences.", ) print(interaction.output_text)
Check the current SDK documentation before combining this with older generate_content or chat examples. Do not mix field names from different APIs.
#Extend only after one request works
Add task instructions, structured output and multimodal inputs using the selected endpoint's documented configuration. Validate returned fields and handle refusal, interruption, missing content and rate limits explicitly.
#AI Studio and Vertex AI
AI Studio is useful for exploring Gemini API prompts and managing its API access. Vertex AI is part of Google Cloud's project, identity and operational environment. Choose using data requirements, available features, regions and costs; neither choice removes the need for access control or evaluation.