شروع سریع رابط برنامهنویسی Gemini
این آموزش سریع به شما نشان میدهد که چگونه کتابخانههای ما را نصب کنید و اولین درخواست API Gemini خود را با استفاده از Interactions API ارسال کنید.
قبل از اینکه شروع کنی
استفاده از API جمینی به یک کلید API نیاز دارد، میتوانید برای شروع یکی را به صورت رایگان ایجاد کنید.
نصب SDK گوگل GenAI
پایتون
با استفاده از پایتون ۳.۹+ ، بسته google-genai را با استفاده از دستور pip زیر نصب کنید:
pip install -q -U google-genai
جاوا اسکریپت
با استفاده از Node.js نسخه ۱۸+ ، کیت توسعه نرمافزاری Google Gen AI را برای TypeScript و JavaScript با استفاده از دستور npm زیر نصب کنید:
npm install @google/genai
اولین درخواست خود را مطرح کنید
در اینجا مثالی آورده شده است که از Interactions API برای ارسال درخواست به Gemini API با استفاده از مدل Gemini 3 Flash استفاده میکند.
اگر کلید API خود را به عنوان متغیر محیطی GEMINI_API_KEY تنظیم کنید، هنگام استفاده از کتابخانههای API Gemini، کلاینت به طور خودکار آن را دریافت میکند. در غیر این صورت، هنگام مقداردهی اولیه کلاینت، باید کلید API خود را به عنوان یک آرگومان ارسال کنید .
توجه داشته باشید که تمام نمونههای کد موجود در مستندات API Gemini فرض میکنند که شما متغیر محیطی GEMINI_API_KEY تنظیم کردهاید.
پایتون
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();
استراحت
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 را در عمل نشان میدهند، بررسی کنید:
،شروع سریع رابط برنامهنویسی Gemini
این آموزش سریع به شما نشان میدهد که چگونه کتابخانههای ما را نصب کنید و اولین درخواست API Gemini خود را با استفاده از Interactions API ارسال کنید.
قبل از اینکه شروع کنی
استفاده از API جمینی به یک کلید API نیاز دارد، میتوانید برای شروع یکی را به صورت رایگان ایجاد کنید.
نصب SDK گوگل GenAI
پایتون
با استفاده از پایتون ۳.۹+ ، بسته google-genai را با استفاده از دستور pip زیر نصب کنید:
pip install -q -U google-genai
جاوا اسکریپت
با استفاده از Node.js نسخه ۱۸+ ، کیت توسعه نرمافزاری Google Gen AI را برای TypeScript و JavaScript با استفاده از دستور npm زیر نصب کنید:
npm install @google/genai
اولین درخواست خود را مطرح کنید
در اینجا مثالی آورده شده است که از Interactions API برای ارسال درخواست به Gemini API با استفاده از مدل Gemini 3 Flash استفاده میکند.
اگر کلید API خود را به عنوان متغیر محیطی GEMINI_API_KEY تنظیم کنید، هنگام استفاده از کتابخانههای API Gemini، کلاینت به طور خودکار آن را دریافت میکند. در غیر این صورت، هنگام مقداردهی اولیه کلاینت، باید کلید API خود را به عنوان یک آرگومان ارسال کنید .
توجه داشته باشید که تمام نمونههای کد موجود در مستندات API Gemini فرض میکنند که شما متغیر محیطی GEMINI_API_KEY تنظیم کردهاید.
پایتون
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();
استراحت
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 را در عمل نشان میدهند، بررسی کنید: