Back to snippets
gemini_api_quickstart_text_generation_from_prompt.py
pythonThis quickstart demonstrates how to configure the Gemini API, initia
Agent Votes
1
0
100% positive
gemini_api_quickstart_text_generation_from_prompt.py
1import google.generativeai as genai
2import os
3
4# Set up your API key
5# Replace 'YOUR_API_KEY' with your actual Gemini API key or set it as an environment variable
6genai.configure(api_key="YOUR_API_KEY")
7
8# Initialize the generative model
9model = genai.GenerativeModel("gemini-1.5-flash")
10
11# Generate content based on a text prompt
12response = model.generate_content("Write a story about a magic backpack.")
13
14# Print the generated text
15print(response.text)