Gemini API 빠른 시작
이 빠른 시작에서는 라이브러리를 설치하고 Interactions API를 사용하여 첫 번째 Gemini API 요청을 만드는 방법을 보여줍니다.
시작하기 전에
Gemini API를 사용하려면 API 키가 필요합니다. 무료로 API 키를 만들어 시작할 수 있습니다.
Google GenAI SDK 설치
Python
Python 3.9 이상을 사용하여 다음 pip 명령어를 사용하여 google-genai 패키지를 설치합니다.
pip install -q -U google-genai
자바스크립트
Node.js v18 이상을 사용하여 다음 npm 명령어를 사용하여 TypeScript 및 JavaScript용 Google 생성형 AI SDK를 설치합니다.
npm install @google/genai
첫 번째 요청하기
다음은 Gemini 3 Flash 모델을 사용하여 Gemini API에 요청을 전송하는 Interactions API를 사용하는 예입니다.
API 키를 환경 변수 GEMINI_API_KEY로 설정하면 Gemini API 라이브러리를 사용할 때 클라이언트에서 자동으로 선택합니다.
그렇지 않으면 클라이언트를 초기화할 때 API 키를 인수로 전달해야 합니다.
Gemini API 문서의 모든 코드 샘플은 환경 변수 GEMINI_API_KEY를 설정했다고 가정합니다.
Python
from google import genai
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain how AI works in a few words"
)
# Print the model's text response
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "text":
print(content_block.text)
자바스크립트
import { GoogleGenAI } from "@google/genai";
// The client gets the API key from the environment variable `GEMINI_API_KEY`.
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain how AI works in a few words",
});
const modelStep = interaction.steps.find(s => s.type === 'model_output');
if (modelStep) {
for (const contentBlock of modelStep.content) {
if (contentBlock.type === 'text') console.log(contentBlock.text);
}
}
}
main();
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain how AI works in a few words"
}'
다음 단계
첫 번째 API 요청을 완료했으므로 Gemini가 작동하는 모습을 보여주는 다음 가이드를 살펴보세요.