Your First Gemini API Call
Get an API key in AI Studio, install google-generativeai, make your first generate_content call, and parse the response structure.
Make a first call in Python to gemini-2.0-flash. Print response.text, the candidate's finish_reason, and usage_metadata.total_token_count. Then intentionally call .text after a hard safety block (e.g. a dangerous prompt) and handle the exception via try/except.
Copy and adapt to your context. Text in angle brackets should be replaced.
I'm integrating the Google Gemini API.
Language: <Python / JavaScript>
Task: <…>
Give me a minimal working example: configure with the key from env,
GenerativeModel("gemini-2.0-flash"), generate_content, safe reading of
text from candidates[].content.parts with a finish_reason check. No extra abstractions.