Flex inference

Gemini Flex API, इन्फ़रेंस टियर है. इसकी मदद से, स्टैंडर्ड दरों की तुलना में 50% कम लागत में इन्फ़रेंस जनरेट किया जा सकता है. हालांकि, इसके लिए आपको अलग-अलग लेटेंसी और पूरी कोशिश के साथ उपलब्धता की सुविधा मिलती है. इसे ऐसे वर्कलोड के लिए डिज़ाइन किया गया है जिनमें लेटेंसी से जुड़ी समस्याएं नहीं होती हैं. साथ ही, इनमें सिंक्रोनस प्रोसेसिंग की ज़रूरत होती है, लेकिन स्टैंडर्ड एपीआई की रीयल-टाइम परफ़ॉर्मेंस की ज़रूरत नहीं होती.

Flex का इस्तेमाल करना

Flex टियर का इस्तेमाल करने के लिए, अपने अनुरोध में service_tier को flex के तौर पर तय करें. डिफ़ॉल्ट रूप से, अगर इस फ़ील्ड को छोड़ दिया जाता है, तो अनुरोधों के लिए स्टैंडर्ड टियर का इस्तेमाल किया जाता है.

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Analyze this dataset for trends...",
    service_tier='flex'
)
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

async function main() {
    const interaction = await client.interactions.create({
        model: 'gemini-3.8-flash',
        input: 'Analyze this dataset for trends...',
        service_tier: 'flex'
    });
    console.log(interaction.output_text);
}
await main();

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ServiceTier;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of("Process this batch job using Flex Tier."))
        .serviceTier(ServiceTier.FLEX)
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -d '{
      "model": "gemini-3.8-flash",
      "input": "Analyze this dataset for trends...",
      "service_tier": "flex"
  }'

Flex इन्फ़रेंस कैसे काम करता है

Gemini Flex इन्फ़रेंस, स्टैंडर्ड एपीआई और बैच एपीआई के 24 घंटे के टर्नअराउंड के बीच के अंतर को कम करता है. यह ऑफ़-पीक, "शेडबल" कंप्यूट क्षमता का इस्तेमाल करके, बैकग्राउंड टास्क और सीक्वेंशियल वर्कफ़्लो के लिए लागत के हिसाब से बेहतर समाधान उपलब्ध कराता है.

सुविधा Flex प्राथमिकता स्टैंडर्ड बैच
कीमत 50% की छूट स्टैंडर्ड से 75 से 100% ज़्यादा फ़ुल टिकट 50% की छूट
लेटेंसी मिनट (1–15 मिनट का टारगेट) कम (सेकंड) सेकंड से मिनट 24 घंटे तक
भरोसेमंद होना पूरी कोशिश (शेडबल) ज़्यादा (नॉन-शेडबल) ज़्यादा / मीडियम-ज़्यादा ज़्यादा (थ्रूपुट के लिए)
इंटरफ़ेस सिंक्रोनस सिंक्रोनस सिंक्रोनस एसिंक्रोनस

मुख्य फ़ायदे

  • लागत के हिसाब से बेहतर: प्रोडक्शन के अलावा अन्य कामों के लिए, बैकग्राउंड एजेंट, और डेटा एनरिचमेंट में काफ़ी बचत होती है.
  • आसानी से इस्तेमाल किया जा सकता है: मौजूदा अनुरोधों में सिर्फ़ एक पैरामीटर जोड़ें.
  • सिंक्रोनस वर्कफ़्लो: यह सीक्वेंशियल एपीआई चेन के लिए सबसे सही है. इसमें अगला अनुरोध, पिछले अनुरोध के आउटपुट पर निर्भर करता है. इस वजह से, एजेंटिक वर्कफ़्लो के लिए यह बैच से ज़्यादा फ़्लेक्सिबल है.

इस्तेमाल के उदाहरण

  • ऑफ़लाइन आकलन: "एलएलएम-एज़-अ-जज" रिग्रेशन टेस्ट या लीडरबोर्ड चलाना.
  • बैकग्राउंड एजेंट: सीक्वेंशियल टास्क, जैसे कि सीआरएम अपडेट, प्रोफ़ाइल बनाना या कॉन्टेंट मॉडरेट करना. इनमें कुछ मिनट की देरी स्वीकार की जा सकती है.
  • कम बजट में रिसर्च: ऐसे ऐकेडमिक एक्सपेरिमेंट जिनमें सीमित बजट में ज़्यादा टोकन वॉल्यूम की ज़रूरत होती है.

दर की सीमाएं

Flex इन्फ़रेंस ट्रैफ़िक, दर की सामान्य सीमाओं में गिना जाता है. इसमें बैच एपीआई की तरह, दर की ज़्यादा सीमाएं नहीं मिलती हैं.

शेडबल क्षमता

Flex ट्रैफ़िक को कम प्राथमिकता दी जाती है. अगर स्टैंडर्ड ट्रैफ़िक में बढ़ोतरी होती है, तो ज़्यादा प्राथमिकता वाले उपयोगकर्ताओं के लिए क्षमता पक्का करने के लिए, Flex के अनुरोधों को रोका या हटाया जा सकता है. अगर आपको ज़्यादा प्राथमिकता वाला इन्फ़रेंस चाहिए, तो प्राथमिकता वाला इन्फ़रेंस देखें

गड़बड़ी के कोड

जब Flex की क्षमता उपलब्ध नहीं होती या सिस्टम में ज़्यादा ट्रैफ़िक होता है, तो एपीआई, गड़बड़ी के स्टैंडर्ड कोड दिखाएगा:

  • 503 कोड वाली गड़बड़ी: सेवा उपलब्ध नहीं है: इस्तेमाल करने की मौजूदा सीमा पूरी हो गई है.
  • 429 कई बार अनुरोध किया गया: दर की सीमाएं या संसाधन खत्म हो गए हैं.

क्लाइंट की ज़िम्मेदारी

  • सर्वर साइड फ़ॉलबैक नहीं: अनचाहे शुल्क से बचने के लिए, अगर Flex की क्षमता पूरी हो जाती है, तो सिस्टम, Flex के अनुरोध को स्टैंडर्ड टियर में अपने-आप अपग्रेड नहीं करेगा.
  • फिर से कोशिश करना: आपको एक्सपोनेन्शियल बैकऑफ़ के साथ, क्लाइंट साइड पर फिर से कोशिश करने का लॉजिक लागू करना होगा.
  • टाइम आउट: ऐसा हो सकता है कि Flex के अनुरोध, क्यू में हों. इसलिए, हमारा सुझाव है कि कनेक्शन के समय से पहले बंद होने से बचने के लिए, क्लाइंट साइड के टाइम आउट को 10 मिनट या उससे ज़्यादा बढ़ाएं.

टाइम आउट विंडो अडजस्ट करना

आपके पास REST API और क्लाइंट लाइब्रेरी के लिए, हर अनुरोध के हिसाब से टाइम आउट कॉन्फ़िगर करने का विकल्प होता है. हमेशा पक्का करें कि क्लाइंट साइड का टाइम आउट, सर्वर की इंतज़ार की तय विंडो के हिसाब से हो. उदाहरण के लिए, Flex की इंतज़ार की क्यू के लिए 600 सेकंड से ज़्यादा. एसडीके, टाइम आउट की वैल्यू मिलीसेकंड में लेते हैं.

हर अनुरोध के हिसाब से टाइम आउट

Python

from google import genai

client = genai.Client(http_options={"timeout": 900000})

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="why is the sky blue?",
    service_tier="flex",
)

JavaScript

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

async function main() {
    const interaction = await client.interactions.create({
        model: "gemini-3.8-flash",
        input: "why is the sky blue?",
        service_tier: "flex",
    }, {timeout: 900000});
}

await main();

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ServiceTier;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of("Process this batch job using Flex Tier."))
        .serviceTier(ServiceTier.FLEX)
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

फिर से कोशिश करने की सुविधा लागू करना

Flex, शेडबल है और इसमें 503 कोड वाली गड़बड़ियां आ सकती हैं. इसलिए, यहां फिर से कोशिश करने का लॉजिक लागू करने का एक उदाहरण दिया गया है. इससे गड़बड़ी वाले अनुरोधों को जारी रखा जा सकता है:

Python

import time
from google import genai

client = genai.Client()

def call_with_retry(max_retries=3, base_delay=5):
    for attempt in range(max_retries):
        try:
            return client.interactions.create(
                model="gemini-3.8-flash",
                input="Analyze this batch statement.",
                service_tier="flex",
            )
        except Exception as e:
            if attempt < max_retries - 1:
                delay = base_delay * (2 ** attempt) # Exponential Backoff
                print(f"Flex busy, retrying in {delay}s...")
                time.sleep(delay)
            else:
                print("Flex exhausted, falling back to Standard...")
                return client.interactions.create(
                    model="gemini-3.8-flash",
                    input="Analyze this batch statement."
                )

interaction = call_with_retry()
print(interaction.output_text)

JavaScript

import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({});

async function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function callWithRetry(maxRetries = 3, baseDelay = 5) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      console.log(`Attempt ${attempt + 1}: Calling Flex tier...`);
      const interaction = await ai.interactions.create({
        model: "gemini-3.8-flash",
        input: "Analyze this batch statement.",
        service_tier: 'flex',
      });
      return interaction;
    } catch (e) {
      if (attempt < maxRetries - 1) {
        const delay = baseDelay * (2 ** attempt);
        console.log(`Flex busy, retrying in ${delay}s...`);
        await sleep(delay * 1000);
      } else {
        console.log("Flex exhausted, falling back to Standard...");
        return await ai.interactions.create({
          model: "gemini-3.8-flash",
          input: "Analyze this batch statement.",
        });
      }
    }
  }
}

async function main() {
    const interaction = await callWithRetry();
    console.log(interaction.output_text);
}

await main();

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ServiceTier;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of("Process this batch job using Flex Tier."))
        .serviceTier(ServiceTier.FLEX)
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

कीमत

Flex इन्फ़रेंस की कीमत, स्टैंडर्ड एपीआई की कीमत का 50% होती है. इसके लिए, हर टोकन के हिसाब से बिल भेजा जाता है.

इस्तेमाल किए जा सकने वाले मॉडल

यहां दिए गए मॉडल, Flex इन्फ़रेंस के साथ काम करते हैं:

मॉडल Flex इन्फ़रेंस
Gemini 3.8 Flash ✔️
Gemini 3.7 Flash ✔️
Gemini 3.6 Flash ✔️
Gemini 3.5 Flash-Lite ✔️
Gemini 3.5 Flash ✔️
Gemini 3.1 Flash-Lite ✔️
Gemini 3.1 Pro का पूर्वावलोकन ✔️
Gemini 3 Flash का पूर्वावलोकन ✔️
Gemini 2.5 Pro ✔️
Gemini 2.5 Flash ✔️
Gemini 2.5 Flash-Lite ✔️

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