Google AI API Tuto

Arvin Liu @ RayAegis

Installation

Python pacakge

Package Name Used for
google-genai
pydantic

generate_content

Simple Usage

from google import genai
client = genai.Client(api_key=os.environ["GOOGLE_AI_API_KEY"])

response = client.models.generate_content(
    model="gemini-2.0-flash-lite",
    contents="""Classify this payload with simple answer and explanation:
    Payload: ```" or ""="```
    Multiple Choice: 
    A) SQL Injection        B) Command Injection
    C) Cross Site Scripting D) Benign payload    
"""
)
print(response.text)
**A) SQL Injection**

**Explanation:**

The payload `" or ""=""` is designed to manipulate the logic of an SQL query.  
The `or ""=""` part is intended to make the query always evaluate to true, effectively bypassing any authentication or authorization checks.  
This is a classic SQL injection technique.
  • Query
  • Response

Config

Config Parameters Value Field Meaning
response_mime_type /
response_schema /
responseJsonSchema
str /
pydantic object /
object
Constraint the output type
temperature float: [0.0, 2.0] low: more deterministic
high: more diverse
Sweden Stockholm +46 555 0077
UK London +44 555 0211
South Korea Seoul +82 555 0138
  • We can use                                                       to manipulate the reponse.
types.GenerateContentConfig

Palette

By Arvin Liu

Palette

  • 7