Google の公式統合 SDK google-genai を使用してください(旧版の google-generative-ai は 2025年11月30日 (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);
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)
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}")