Gemini
Last Update: 7/13/2025
This quickstart shows you how to install our libraries and make your first Gemini API request.
Before you begin
You need a Gemini API key. If you don't already have one, you can get it for free in Google AI Studio.
When making requests, you can provide your API key in the Authorization
header.
Header | Value |
---|---|
Authorization | Bearer YOUR_API_KEY |
Install the Google GenAI SDK
Using Python 3.9+, install the google-genai
package using the following pip command:
pip install -q -U google-genai
Make your first request
Here is an example that uses generateContent
method to send a request to the Gemini API using Gemini 1.5 flash model.
from google import genai
# The client library automatically handles authentication by putting
# your API key in the Authorization header.
client = genai.Client(api_key="YOUR_API_KEY")
response = client.models.generate_content(
model="gemini-1.5-flash", contents="Explain how AI works in a few words"
)
print(response.text)
"Thinking" is on by default on many of our code samples
Many code samples on this site use the Gemini 1.5 Flash model, which has the "thinking" feature enabled by default to enhance response quality. You should be aware that this may increase response time and token usage. If you prioritize speed or wish to minimize costs, you can disable this feature by setting the thinking budget to zero, as shown in the examples below. For more details, see the thinking guide.
Note: Thinking is only available on Gemini 1.5 series models and can't be disabled on Gemini 1.5 Pro.
from google import genai
from google.genai import types
client = genai.Client(api_key="GEMINI_API_KEY")
response = client.models.generate_content(
model="gemini-1.5-flash",
contents="Explain how AI works in a few words",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget=0) # Disables thinking
),
)
print(response.text)
What's next
Now that you made your first API request, you might want to explore the following guides that show Gemini in action:
- Thinking
- Text generation
- Vision
- Long context