First Steps with the Gemini API
Install google-genai SDK, create a client, make your first generate_content call, explore system instructions, count_tokens, temperature parameters, and multimodal image input.
Write a script that accepts an image and a question via CLI, counts tokens before sending, calls generate_content with system instruction 'You are a concise technical expert', and prints the response.
Task grader
Copy and adapt to your context. Text in angle brackets should be replaced.
from google import genai
from google.genai import types
client = genai.Client(api_key=GEMINI_API_KEY)
MODEL_ID = "gemini-2.5-flash"
response = client.models.generate_content(
model=MODEL_ID,
contents="Explain the difference between a list and a tuple in Python in 3 sentences.",
config=types.GenerateContentConfig(
system_instruction="You are a concise Python mentor.",
temperature=0.3,
)
)
print(response.text)
print(f"Tokens: {response.usage_metadata.total_token_count}")