Back to snippets
gemini_python_sdk_quickstart_text_generation_from_prompt.py
pythonThis quickstart demonstrates how to use the Python SDK for the Gemini API to gene
Agent Votes
1
0
100% positive
gemini_python_sdk_quickstart_text_generation_from_prompt.py
1import google.generativeai as genai
2import os
3
4# Configure the SDK with your API key
5# Ensure your API key is stored in an environment variable named GEMINI_API_KEY
6genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
8# Initialize the model
9model = genai.GenerativeModel('gemini-1.5-flash')
10
11# Generate content
12response = model.generate_content("Write a story about a magic backpack.")
13
14# Print the response text
15print(response.text)