Gemini API का इस्तेमाल शुरू करने का तरीका

इस क्विकस्टार्ट में, हमारी लाइब्रेरी इंस्टॉल करने और Interactions API का इस्तेमाल करके, Gemini API को पहला अनुरोध भेजने का तरीका बताया गया है.

शुरू करने से पहले

Gemini API का इस्तेमाल करने के लिए, एपीआई पासकोड की ज़रूरत होती है. इसे मुफ़्त में बनाया जा सकता है.

Gemini API पासकोड बनाना

Google GenAI SDK टूल इंस्टॉल करना

पहला अनुरोध भेजना

यहां एक उदाहरण दिया गया है, जिसमें Gemini 3 Flash मॉडल का इस्तेमाल करके, Gemini API को अनुरोध भेजने के लिए Interactions API का इस्तेमाल किया गया है.

अगर आपने अपने एपीआई पासकोड को एनवायरमेंट वैरिएबल GEMINI_API_KEY के तौर पर सेट किया है, तो Gemini 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)

JavaScript

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"
  }'

आगे क्या करना है

अब आपने एपीआई को पहला अनुरोध भेज दिया है. इसके बाद, यहां दी गई गाइड एक्सप्लोर की जा सकती हैं. इनमें Gemini के काम करने के तरीके के बारे में बताया गया है: