Unode
User GuideAPI ReferenceHelp & SupportBusiness Cooperation

Google Gemini Chat

Introduction

Google Gemini API supports generating content using images, audio, code, tools, etc. Given input GenerateContentRequest generates model responses. Supports text generation, visual understanding, audio processing, long context, code execution, JSON schema, function calling, and many other features.

Supported Models

Currently supported models include:

ModelDescription
gemini-3-flash-previewFrontier-class performance rivaling larger models at a fraction of the cost (preview)
gemini-3.1-flash-liteFrontier-class performance rivaling larger models at a fraction of the cost
gemini-3.1-pro-previewAdvanced intelligence, complex problem-solving, and powerful agentic and vibe coding capabilities (preview)
gemini-3.5-flash-liteFastest, most cost-effective 3.5 model, built for high-throughput execution
gemini-3.5-flashLegacy Flash model providing baseline speed and foundational performance for routine, high-throughput workloads
gemini-3.6-flashPrevious-generation Flash model balancing speed and multimodal capabilities across general agentic and everyday tasks
gemini-3.7-flashIntelligent everyday driver, built for complex coding, agentic workflows, and reliable multi-step execution
gemini-3.8-flashMost intelligent Flash model yet, built for long-horizon coding and autonomous agents

Request Examples

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[{"text": "Write a story about a magic backpack."}]
        }]
       }'
# Use temporary file to save base64 encoded image data
TEMP_B64=$(mktemp)
trap 'rm -f "$TEMP_B64"' EXIT
base64 $B64FLAGS $IMG_PATH > "$TEMP_B64"

# Use temporary file to save JSON payload
TEMP_JSON=$(mktemp)
trap 'rm -f "$TEMP_JSON"' EXIT

cat > "$TEMP_JSON" << EOF
{
  "contents": [{
    "parts":[
      {"text": "Tell me about this instrument"},
      {
        "inline_data": {
          "mime_type":"image/jpeg",
          "data": "$(cat "$TEMP_B64")"
        }
      }
    ]
  }]
}
EOF

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d "@$TEMP_JSON"
cat > tools.json << EOF
{
  "function_declarations": [
    {
      "name": "enable_lights",
      "description": "Turn on the lighting system."
    },
    {
      "name": "set_light_color",
      "description": "Set the light color. Lights must be enabled for this to work.",
      "parameters": {
        "type": "object",
        "properties": {
          "rgb_hex": {
            "type": "string",
            "description": "The light color as a 6-digit hex string, e.g. ff0000 for red."
          }
        },
        "required": [
          "rgb_hex"
        ]
      }
    },
    {
      "name": "stop_lights",
      "description": "Turn off the lighting system."
    }
  ]
} 
EOF

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
  -H 'Content-Type: application/json' \
  -d @<(echo '
  {
    "system_instruction": {
      "parts": {
        "text": "You are a helpful lighting system bot. You can turn lights on and off, and you can set the color. Do not perform any other tasks."
      }
    },
    "tools": ['$(cat tools.json)'],

    "tool_config": {
      "function_calling_config": {"mode": "auto"}
    },

    "contents": {
      "role": "user",
      "parts": {
        "text": "Turn on the lights please."
      }
    }
  }
')
curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
-H 'Content-Type: application/json' \
-d '{
    "contents": [{
      "parts":[
        {"text": "List 5 popular cookie recipes"}
        ]
    }],
    "generationConfig": {
        "response_mime_type": "application/json",
        "response_schema": {
          "type": "ARRAY",
          "items": {
            "type": "OBJECT",
            "properties": {
              "recipe_name": {"type":"STRING"},
            }
          }
        }
    }
}'

File Upload Limitations

Only supports uploading audio via inline_data in base64 format, does not support file_data.file_uri or File API.

# Use File API to upload audio data to API request
# Use base64 inline_data to upload audio data to API request
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
  B64FLAGS="--input"
else
  B64FLAGS="-w0"
fi
AUDIO_B64=$(base64 $B64FLAGS "$AUDIO_PATH")

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Please describe this audio file."},
        {"inline_data": {"mime_type": "audio/mpeg", "data": "'$AUDIO_B64'"}}
      ]
    }]
  }'

File Upload Limitations

Only supports uploading video via inline_data in base64 format, does not support file_data.file_uri or File API.

# Use File API to upload video data to API request
# Use base64 inline_data to upload video data to API request
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
  B64FLAGS="--input"
else
  B64FLAGS="-w0"
fi
VIDEO_B64=$(base64 $B64FLAGS "$VIDEO_PATH")

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Transcribe the audio from this video and provide visual descriptions."},
        {"inline_data": {"mime_type": "video/mp4", "data": "'$VIDEO_B64'"}}
      ]
    }]
  }'

File Upload Limitations

仅支持通过 inline_data 以 base64 方式上传 PDF,不支持 file_data.file_uri 或 File API。

MIME_TYPE=$(file -b --mime-type "${PDF_PATH}")
# 使用 base64 inline_data 上传 PDF 文件到 API 请求
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
  B64FLAGS="--input"
else
  B64FLAGS="-w0"
fi
PDF_B64=$(base64 $B64FLAGS "$PDF_PATH")

echo $MIME_TYPE

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Can you add a few more lines to this poem?"},
        {"inline_data": {"mime_type": "application/pdf", "data": "'$PDF_B64'"}}
      ]
    }]
  }'
curl https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [
        {"role":"user",
         "parts":[{
           "text": "Hello"}]},
        {"role": "model",
         "parts":[{
           "text": "Great to meet you. What would you like to know?"}]},
        {"role":"user",
         "parts":[{
           "text": "I have two dogs in my house. How many paws are in my house?"}]},
      ]
    }'
curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:streamGenerateContent?alt=sse&key=$API_KEY" \
    -H 'Content-Type: application/json' \
    --no-buffer \
    -d '{
      "contents": [{
        "parts": [{"text": "写一个关于魔法背包的故事"}]
      }]
    }'
curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts": [{"text": "计算斐波那契数列的第10项"}]
      }],
      "tools": [{
        "codeExecution": {}
      }]
    }'
curl https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
        "contents": [{
            "parts":[
                {"text": "Explain how AI works"}
            ]
        }],
        "generationConfig": {
            "stopSequences": [
                "Title"
            ],
            "temperature": 1.0,
            "maxOutputTokens": 800,
            "topP": 0.8,
            "topK": 10
        }
    }'
echo '{
    "safetySettings": [
        {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"},
        {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}
    ],
    "contents": [{
        "parts":[{
            "text": "'I support Martians Soccer Club and I think Jupiterians Football Club sucks! Write a ironic phrase about them.'"}]}]}' > request.json

curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d @request.json
curl "https://www.unodetech.xyz/v1beta/models/gemini-3.8-flash:generateContent?key=$API_KEY" \
-H 'Content-Type: application/json' \
-d '{ "system_instruction": {
    "parts":
      { "text": "You are a cat. Your name is Neko."}},
    "contents": {
      "parts": {
        "text": "Hello there"}}}'

Request

Endpoints

Generate Content

POST https://www.unodetech.xyz/v1beta/{model=models/*}:generateContent

Stream Generate Content

POST https://www.unodetech.xyz/v1beta/{model=models/*}:streamGenerateContent

Authentication Method

Include API key in the request URL:

?key=$API_KEY

Where $API_KEY is your Google AI API key.

Path Parameters

Request Body Parameters

Response

GenerateContentResponse

Answer from models that support multiple candidate answers. The system reports safety ratings and content filtering for the prompt and each candidate.

Full response example

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "你好!我是 Gemini,一个由 Google 开发的人工智能助手。我可以帮助您解答问题、提供信息、协助写作、代码编程等多种任务。请告诉我有什么可以为您效劳的!"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE",
          "blocked": false
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH", 
          "probability": "NEGLIGIBLE",
          "blocked": false
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE",
          "blocked": false
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE",
          "blocked": false
        }
      ],
      "tokenCount": 47
    }
  ],
  "promptFeedback": {
    "safetyRatings": [
      {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "probability": "NEGLIGIBLE"
      }
    ]
  },
  "usageMetadata": {
    "promptTokenCount": 4,
    "candidatesTokenCount": 47,
    "totalTokenCount": 51,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 4
      }
    ],
    "candidatesTokensDetails": [
      {
        "modality": "TEXT", 
        "tokenCount": 47
      }
    ]
  },
  "modelVersion": "gemini-3.8-flash",
  "responseId": "response-12345"
}

Feature Interactions

The fields below are not additional top-level parameters. Each feature is enabled by a field in the request tree and, when applicable, produces data at a corresponding path in GenerateContentResponse.

Code Execution

Enable code execution with tools[].codeExecution. The generated code and its execution result are returned as content parts:

Request:  tools[].codeExecution
Response: candidates[].content.parts[].executableCode
          candidates[].content.parts[].codeExecutionResult
{
  "tools": [
    {
      "codeExecution": {}
    }
  ],
  "contents": [
    {
      "parts": [
        {
          "text": "Calculate the tenth Fibonacci number."
        }
      ]
    }
  ]
}

Grounding and URL Context

Enable Google Search grounding or URL retrieval through the tools array. Supporting sources and retrieval status are returned as candidate metadata:

Request:  tools[].googleSearch
Response: candidates[].groundingMetadata

Request:  tools[].urlContext
Response: candidates[].urlContextMetadata

Grounding chunks contain the retrieved sources. Grounding supports associate portions of the generated answer with those chunks.

Thinking

Thinking is configured inside generationConfig:

Request:  generationConfig.thinkingConfig
Response: candidates[].content.parts[]   (thought parts, when requested and available)
          usageMetadata.thoughtsTokenCount

Set includeThoughts to request available thought summaries and use thinkingBudget or thinkingLevel only with models that support those controls.

Speech Generation

Speech output requires an audio response modality and a speech configuration:

Request:  generationConfig.responseModalities
          generationConfig.speechConfig
Response: candidates[].content.parts[]   (audio media parts)

Single-voice settings belong under speechConfig.voiceConfig. Multi-speaker settings belong under speechConfig.multiSpeakerVoiceConfig; the two configurations are mutually exclusive.

Log Probabilities

Enable log probabilities in the request and read the token-level results from each candidate:

Request:  generationConfig.responseLogprobs
          generationConfig.logprobs
Response: candidates[].avgLogprobs
          candidates[].logprobsResult

logprobs is only valid when responseLogprobs is enabled.

Safety

safetySettings controls the blocking thresholds applied to the request and generated candidates. Ratings are returned separately:

Request:  safetySettings[]
Response: promptFeedback.safetyRatings[]
          candidates[].safetyRatings[]

A blocked prompt is reported through promptFeedback.blockReason. A candidate stopped for safety reasons reports the condition through finishReason and safetyRatings.

Multimodal Processing

Supply inline or uploaded media as content parts. Resolution is an input setting, while modality token counts are response metadata:

Request:  contents[].parts[].inlineData
          contents[].parts[].fileData
          generationConfig.mediaResolution
Response: usageMetadata.promptTokensDetails[]
          usageMetadata.candidatesTokensDetails[]

Supported media depends on the selected model. Common modalities include text, images, audio, video, and PDF documents.

Error Handling

Common Error Codes

Error CodeDescription
400Request format error or invalid parameter
401API key invalid or missing
403Insufficient permissions or quota limit
429Request frequency too high
500Server internal error

Detailed Error Code Explanations

Error CodeStatusDescriptionSolution
400INVALID_ARGUMENTRequest parameter invalid or format errorCheck request parameter format and required fields
400FAILED_PRECONDITIONPrecondition for the request not metEnsure API call prerequisites are met
401UNAUTHENTICATEDAPI key invalid, missing, or expiredCheck API key validity and format
403PERMISSION_DENIEDInsufficient permissions or quota exhaustedCheck API key permissions or upgrade quota
404NOT_FOUNDSpecified model or resource does not existVerify model name and resource path
413PAYLOAD_TOO_LARGERequest body too largeReduce input content size or process in batches
429RESOURCE_EXHAUSTEDRequest frequency exceeded or quota insufficientReduce request frequency or wait for quota reset
500INTERNALServer internal errorRetry the request, if persistent contact support
503UNAVAILABLEService temporarily unavailableWait for a period and retry
504DEADLINE_EXCEEDEDRequest timed outReduce input size or retry the request

Error Response Example

{
  "error": {
    "code": 400,
    "message": "Invalid argument: contents",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "contents",
            "description": "contents is required"
          }
        ]
      }
    ]
  }
}

Last updated on