Content पर जाएं

Google Gemini GenerateContent

POST/v1beta/models/{model}:generateContent

native Gemini request भेजें और Gemini-compatible response पाएँ। Streaming के लिए streamGenerateContent इस्तेमाल करें।

Path parameters

stringmodelज़रूरी

Bare Google model name, जैसे gemini-3.5-flash। SandBase इसे google/{model} के रूप में resolve करता है।

Request body

वैकल्पिक<array>contents

role और parts से बने Gemini conversation contents।

वैकल्पिक<object>systemInstruction

Gemini Content रूप में text system instruction।

वैकल्पिक<object>generationConfig

Sampling, output length, structured output और thinking settings।

वैकल्पिक<array>tools

Function declarations या समर्थित Gemini built-in tool configuration।

वैकल्पिक<object>toolConfig

Gemini function-calling policy।

वैकल्पिक<array>safetySettings

Gemini safety categories और thresholds।

वैकल्पिक<string>cachedContent

समर्थित होने पर आगे भेजा जाने वाला Gemini cached-content resource।

प्रमाणीकरण ​

Google-compatible requests SandBase API key को x-goog-api-key, Authorization: Bearer …, या key query parameter में, इसी प्राथमिकता क्रम में, भेज सकते हैं। Header को प्राथमिकता दें: query-string credentials proxy logs और browser history में दिख सकते हैं।

स्ट्रीमिंग ​

Method suffix को :streamGenerateContent से बदलें। Query parameter के बिना, SandBase Google-compatible response objects को streamed JSON array के रूप में लौटाता है। Server-Sent Events के लिए ?alt=sse जोड़ें:

bash
curl -N -X POST \
  "https://api.sandbase.ai/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: $SANDBASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"role":"user","parts":[{"text":"Write a short greeting."}]}]}'

नेटिव इमेज जनरेशन ​

इन image models के लिए dedicated native GenerateContent mappings हैं:

हर model पेज पर उसकी token कीमतें और प्रति image लागत दी गई है।

इन mappings के लिए, SandBase request और response payloads को Chat Completions के ज़रिए convert किए बिना आगे भेजता है। इससे image parts, response modalities और provider-defined fields बने रहते हैं। URL में bare model name इस्तेमाल करें; उदाहरण के लिए, path में google/gemini-3.1-flash-image gemini-3.1-flash-image बन जाता है।

Image edit करें ​

Source image को text instruction के बगल में एक inlineData part के रूप में जोड़ें। भेजे जा रहे bytes का MIME type इस्तेमाल करें:

json
{
  "contents": [{
    "role": "user",
    "parts": [
      {"text": "Keep the subject unchanged and turn the background into a paper-cut landscape."},
      {"inlineData": {"mimeType": "image/png", "data": "<base64-input-image>"}}
    ]
  }],
  "generationConfig": {"responseModalities": ["IMAGE"], "imageConfig": {"imageSize": "1K"}}
}

Google Gen AI SDK इस्तेमाल करें ​

आधिकारिक SDK को SandBase की ओर point करें और अपनी SandBase API key इस्तेमाल करें:

python
from google import genai
from google.genai import types

client = genai.Client(
    api_key="YOUR_SANDBASE_API_KEY",
    http_options=types.HttpOptions(base_url="https://api.sandbase.ai"),
)

response = client.models.generate_content(
    model="gemini-nano-banana-2.1",
    contents="Create a wide editorial illustration of a solar-powered city at sunrise.",
    config=types.GenerateContentConfig(
        response_modalities=["IMAGE"],
        image_config=types.ImageConfig(aspect_ratio="16:9", image_size="1K"),
    ),
)

for part in response.candidates[0].content.parts:
    if part.inline_data:
        with open("output.jpg", "wb") as f:
            f.write(part.inline_data.data)

Streaming के लिए, उसी body के साथ :streamGenerateContent?alt=sse (SDK: generate_content_stream) call करें।

प्रतिक्रिया प्रबंधन ​

Generated media को लौटाए गए candidate parts से पढ़ें। चूँकि ये models native passthrough इस्तेमाल करते हैं, provider-defined field casing और MIME metadata वैसे ही लौटाए जाते हैं जैसे मिले थे। File extension चुनने से पहले base64 payload को decode करें और असली media bytes की पुष्टि करें।

Routing और translation की सीमाएँ ​

SandBase केवल वही providers चुनता है जो अनुरोधित native Gemini protocol का समर्थन करते हैं। अगर चुने गए model का कोई compatible native mapping नहीं है, तो request किसी अलग protocol वाले provider पर fallback करने के बजाय विफल हो जाता है।

Translated GenerateContent path इस्तेमाल करने वाले models text, function calls और responses, inline image/* data, और public HTTP(S) image references का समर्थन करते हैं। वह translated path असमर्थित inline MIME types, private Google Files या gs:// references, multiple candidates, और असमर्थित response modalities को Google-style 400 INVALID_ARGUMENT response के साथ अस्वीकार करता है। ऊपर सूचीबद्ध image-generation mappings raw passthrough इस्तेमाल करती हैं और इन translation-only limits के अधीन नहीं हैं; लौटाए गए media fields को चुने गए provider के response के अनुसार validate करें।