원하는 패키지는 google-genai
공식 Python SDK 는 google-genai (pip 이름은 hyphen, import 이름은 dot). legacy google-generativeai 패키지를 대체해 — 그건 2025 년 11 월 EOL. 튜토리얼이 import google.generativeai as genai 쓴다면 그건 EOL 이전이고 surface 가 그 밑에서 바뀌었어.
설치
main 패키지 한 개 + aiohttp 통한 더 빠른 async 위한 optional extra:
어디서나 쓸 import 세 개
from google import genai— client factory.from google.genai import types— config dataclass (GenerateContentConfig,Tool,Part,HarmCategory등).from google.genai import errors— exception class (APIError,ClientError,ServerError).
Client 생성 패턴
흔한 모양 세 가지:
- Implicit env —
genai.Client()가GEMINI_API_KEY또는GOOGLE_API_KEY읽음. - Explicit key —
genai.Client(api_key='...'). 테스트나 여러 key 다룰 때 유용. - Vertex AI —
genai.Client(vertexai=True, project='...', location='...').
Client instance 하나가 sync 와 async 둘 다 핸들 — async surface 는 client.aio.models 와 client.aio.chats 에 살아.