2026년 1월 19일 기준

Gemini API

API Key 발급받기

  • API 키 만들기 버튼 클릭

사용 가능한 모델 목록

Python 에서 사용하기

설치

1
2
3
4
5
# uv
uv add google-genai

# pip...
pip install google-genai

기본 사용법(싱글턴)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from google import genai

api_key = "abc...."

def gemini_api(prompt:str):
    # 1. 클라이언트 초기화 (발급받은 API 키 입력)
    client = genai.Client(api_key=api_key)

    # 2. 메시지 전송 및 응답 받기
    response = client.models.generate_content(
        model="gemini-2.5-flash", # 사용하고자 하는 모델명
        contents=prompt
    )

    # 3. 결과 출력
    return response.text

Reference

google ai studio
Gemini API Doc

Comments