Call the official Gemini generateContent format through APIYI: google-genai SDK setup, streaming, thinking_level controls, and thought signatures.
APIYI fully supports the official Gemini native format (the /v1beta generateContent endpoint): point the base_url at https://api.apiyi.com and your existing Gemini code and official SDKs migrate seamlessly — no format conversion needed.This page is based on the official Google documentation (ai.google.dev/gemini-api/docs, as of June 2026). All examples are copy-paste ready.
Use Google’s official unified SDK google-genai (the legacy google-generative-ai was sunset on November 30, 2025 (UTC)):
pip install google-genai
from google import genaiclient = genai.Client( api_key="YOUR_API_KEY", # your APIYI key http_options={"base_url": "https://api.apiyi.com"})response = client.models.generate_content( model="gemini-3.5-flash", contents="Introduce yourself in one sentence")print(response.text)
import { GoogleGenAI } from '@google/genai';const ai = new GoogleGenAI({ apiKey: 'YOUR_API_KEY', httpOptions: { baseUrl: 'https://api.apiyi.com' }});const response = await ai.models.generateContent({ model: 'gemini-3.5-flash', contents: 'Introduce yourself in one sentence'});console.log(response.text);
The base_url is https://api.apiyi.com (without/v1) — different from the OpenAI-compatible format’s https://api.apiyi.com/v1. Use your APIYI key, not a Google AI Studio key.
stream = client.models.generate_content_stream( model="gemini-3.5-flash", contents="Write a short essay on quantum computing")for chunk in stream: print(chunk.text, end="", flush=True)
Gemini models think by default, and the two generations use different parameters — mixing them raises an error:
Model series
Parameter
Values
Gemini 3 / 3.1 / 3.5
thinking_level
minimal (Flash family only) / low / high (default)
Gemini 2.5
thinking_budget
token cap (e.g. 0–8192); model auto-controls if unset
Passing both thinking_level and thinking_budget to a Gemini 3 series model returns an error — pick one (use thinking_level for the 3 series).
from google.genai import types# Gemini 3 series: level-based controlresponse = client.models.generate_content( model="gemini-3.5-flash", contents="Prove that the square root of 2 is irrational", config=types.GenerateContentConfig( thinking_config=types.ThinkingConfig(thinking_level="high") ))# Gemini 2.5 series: token-budget controlresponse = client.models.generate_content( model="gemini-2.5-flash", contents="Simple question, be quick", config=types.GenerateContentConfig( thinking_config=types.ThinkingConfig(thinking_budget=0) # thinking off ))
Choosing a level: minimal for low-latency simple tasks (classification, extraction); low for routine chat; high for complex reasoning and code. Thinking tokens bill at the output rate — higher levels cost more.
Thought summaries: include_thoughts=True returns a summary of the reasoning (parts where part.thought is True)
Thought signatures: encrypted reasoning state introduced with Gemini 3. In multi-turn conversations (especially function calling), pass the thought_signature from the response back unchanged so the model can continue its reasoning chain. Official SDKs handle this automatically; don’t strip the field in hand-written REST calls — see Function Calling
response = client.models.generate_content( model="gemini-3.5-flash", contents="Analyze the time complexity of: def fib(n): return n if n <= 1 else fib(n-1) + fib(n-2)", config=types.GenerateContentConfig( thinking_config=types.ThinkingConfig(thinking_level="high", include_thoughts=True) ))for part in response.candidates[0].content.parts: if getattr(part, "thought", False): print(f"[Thought summary] {part.text}") else: print(f"[Final answer] {part.text}")
Current workhorse — beats 3.1 Pro on several benchmarks, 1M context
gemini-3.1-pro-preview
$1.80
$10.80
Pro flagship
gemini-3-pro-preview
$1.80
$10.80
Previous Pro
gemini-3-flash-preview
$0.44
$2.64
Light and fast
gemini-3.1-flash-lite
$0.25
$1.50
Ultra-budget
gemini-2.5-pro
$1.25
$10.00
2.5-series Pro
gemini-2.5-flash
$0.30
$2.40
2.5-series workhorse
gemini-2.5-flash-lite
$0.10
$0.40
Cheapest
Some models have -thinking / -nothinking alias variants (e.g. gemini-3-flash-preview-nothinking) that pin thinking on/off — handy for clients where you can’t change request parameters. Full list: Models & Pricing.
The Files API is not supported (client.files.upload()); media must be passed inline and each file must stay under 20MB — see Multimodal & Code Execution
Cache discounts and hit-rate expectations: Cache Billing