Skip to content
Trang này chưa có bản dịch sang ngôn ngữ của bạn, nên hiện đang được hiển thị bằng tiếng Anh.

Gemini Native Format

Call Gemini models using Google Native API format

← Toàn bộ tài liệu
POST/v1beta/models/gemini-3.5-flash:generateContent
  • Synchronous processing mode with real-time response
  • Minimal parameters for quick start
json
{
  "error": {
    "code": 502,
    "message": "Bad gateway, service temporarily unavailable",
    "status": "BAD_GATEWAY"
  }
}
json
{
  "error": {
    "code": 503,
    "message": "Service temporarily unavailable",
    "status": "UNAVAILABLE"
  }
}

Ví dụ request

curl --request POST \
  --url https://api.apisea.ai/v1beta/models/gemini-3.5-flash:generateContent \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Hello, please introduce yourself"
        }
      ]
    }
  ]
}'

Authorizations

Authorizationstringrequired

All API endpoints require Bearer Token authentication

Get your API Key:

Visit the API Key Management Page to get your API Key

Add it to the request header:

text
Authorization: Bearer YOUR_API_KEY

Path Parameters

modelstringrequired

Model name

The examples use gemini-3.5-flash, which you can replace with other supported Gemini models:

  • gemini-3.5-flash - Gemini 3.5 Flash
  • gemini-3.1-pro-preview - Gemini 3.1 Pro Preview
  • gemini-3-pro-preview - Gemini 3 Pro Preview
  • gemini-3.5-flash - Gemini 2.5 Pro
methodenum\required

Generation method (recommended: generateContent for quick start):

  • generateContent: Wait for complete response and return at once
  • streamGenerateContent: Stream response, return content in chunks

Available options: generateContent, streamGenerateContent

Body

contentsarrayrequired

List of conversation contents

Minimum 1 message required

contents object structure

rolestringrequired

Role type:

  • user: User message
  • model: Model response (used in conversation history)
partsarrayrequired

Message content parts

parts object structure

textstring

Text content

inlineDataobject

Inline data (for multimodal input)

inlineData properties

mimeTypestring

MIME type, e.g. image/jpeg, image/png

datastring

Base64 encoded data

fileDataobject

Provide multimodal content, such as video, through a file URI.

fileData properties

mimeTypestring

File MIME type, such as video/mp4.

fileUristring

File URI, such as an HTTP(S) URL for a video file.

parts example: analyze a video URL

Use fileData to provide the video URL and MIME type, and include an analysis prompt in the same message. This example asks the model to list the main events in chronological order with timestamps.

bash
curl 'https://api.apisea.ai/v1beta/models/gemini-3.1-pro-preview:generateContent' \
  -H 'Authorization: Bearer YOUR_APISea_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "fileData": {
              "mimeType": "video/mp4",
              "fileUri": "https://storage.googleapis.com/cloud-samples-data/generative-ai/video/pixel8.mp4"
            }
          },
          {
            "text": "Analyze the video, list the main events in chronological order, and include timestamps."
          }
        ]
      }
    ],
    "generationConfig": {
      "maxOutputTokens": 2048
    }
  }'

Example:

json
[
  {
    "role": "user",
    "parts": [{ "text": "Hello, please introduce yourself" }]
  }
]
generationConfigobject

Generation configuration (optional)

generationConfig properties

temperaturenumber

Controls output randomness, range 0.0-2.0

  • Lower values make output more deterministic
  • Higher values make output more random

Default: 1.0

maxOutputTokensinteger

Maximum number of tokens to generate

Different models have different maximum limits

topPnumber

Nucleus sampling parameter, range 0.0-1.0

Controls the probability mass considered during sampling

topKinteger

Top-K sampling parameter

Sample only from the K most probable tokens at each step

stopSequencesarray

List of stop sequences

Stop generation when these sequences are encountered

safetySettingsarray

Safety settings (optional)

safetySettings object structure

categorystring

Safety category:

  • HARM_CATEGORY_HATE_SPEECH: Hate speech
  • HARM_CATEGORY_DANGEROUS_CONTENT: Dangerous content
  • HARM_CATEGORY_HARASSMENT: Harassment
  • HARM_CATEGORY_SEXUALLY_EXPLICIT: Sexually explicit content
thresholdstring

Threshold level:

  • BLOCK_NONE: Don't block
  • BLOCK_ONLY_HIGH: Block only high risk
  • BLOCK_MEDIUM_AND_ABOVE: Block medium and above risk
  • BLOCK_LOW_AND_ABOVE: Block low and above risk

Response

candidatesarray

List of candidate responses

candidates object structure

contentobject

Generated content

content properties

rolestring

Role, typically model

partsarray

List of content parts

parts object

textstring

Generated text content

finishReasonstring

Finish reason:

  • STOP: Normal completion
  • MAX_TOKENS: Maximum token limit reached
  • SAFETY: Stopped for safety reasons
  • RECITATION: Stopped due to recitation
  • OTHER: Other reasons
indexinteger

Index of the candidate response

safetyRatingsarray

List of safety ratings

safetyRatings object

categorystring

Safety category

probabilitystring

Probability level: NEGLIGIBLE, LOW, MEDIUM, HIGH

promptFeedbackobject

Prompt feedback information

promptFeedback properties

safetyRatingsarray

Safety ratings for the prompt

blockReasonstring

Block reason (if prompt was blocked)

usageMetadataobject

Usage statistics

usageMetadata properties

promptTokenCountinteger

Number of tokens in the prompt

candidatesTokenCountinteger

Number of tokens in candidate responses

totalTokenCountinteger

Total number of tokens consumed

thoughtsTokenCountinteger

Number of tokens used for thinking (if applicable)

promptTokensDetailsarray

Prompt token details

promptTokensDetails object

modalitystring

Modality type: TEXT, IMAGE, etc.

tokenCountinteger

Number of tokens for this modality

Phản hồi

{
  "code": 200,
  "data": {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "Hello! I'm pleased to introduce myself.\n\nI am a large language model, trained and developed by Google..."
            }
          ]
        },
        "finishReason": "STOP",
        "index": 0,
        "safetyRatings": [
          {
            "category": "HARM_CATEGORY_HATE_SPEECH",
            "probability": "NEGLIGIBLE"
          }
        ]
      }
    ],
    "promptFeedback": {
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        }
      ]
    ]
  },
  "usageMetadata": {
    "promptTokenCount": 4,
    "candidatesTokenCount": 611,
    "totalTokenCount": 2422,
    "thoughtsTokenCount": 1807,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 4
      }
    ]
  }
}

Phát hiện lỗi trong tài liệu này? Gửi email đến support@apisea.ai.