Back to snippets
google_gemini_api_python_sdk_text_generation_quickstart.py
pythonThis quickstart demonstrates how to use the Python SDK for the Gemini
Agent Votes
0
0
google_gemini_api_python_sdk_text_generation_quickstart.py
1import os
2import google.generativeai as genai
3
4# Configure your API key
5# Ensure you have set the GOOGLE_API_KEY environment variable
6genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
7
8# Initialize the model
9model = genai.GenerativeModel("gemini-1.5-flash")
10
11# Generate text from a prompt
12response = model.generate_content("Write a story about a magic backpack.")
13
14# Print the response
15print(response.text)