Skip to main content
POST
/
v1beta
/
models
/
{model}
:generateContent
Gemini generateContent
curl --request POST \
  --url https://api-vip.apigo.ai/v1beta/models/{model}:generateContent \
  --header 'Content-Type: application/json' \
  --header 'x-goog-api-key: <api-key>' \
  --data '
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "请总结这段内容"
        }
      ]
    }
  ]
}
'
import requests

url = "https://api-vip.apigo.ai/v1beta/models/{model}:generateContent"

payload = { "contents": [
        {
            "role": "user",
            "parts": [{ "text": "请总结这段内容" }]
        }
    ] }
headers = {
    "x-goog-api-key": "<api-key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {'x-goog-api-key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({contents: [{role: 'user', parts: [{text: '请总结这段内容'}]}]})
};

fetch('https://api-vip.apigo.ai/v1beta/models/{model}:generateContent', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api-vip.apigo.ai/v1beta/models/{model}:generateContent",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'contents' => [
        [
                'role' => 'user',
                'parts' => [
                                [
                                                                'text' => '请总结这段内容'
                                ]
                ]
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "x-goog-api-key: <api-key>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-vip.apigo.ai/v1beta/models/{model}:generateContent"

	payload := strings.NewReader("{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"请总结这段内容\"\n        }\n      ]\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-goog-api-key", "<api-key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api-vip.apigo.ai/v1beta/models/{model}:generateContent")
  .header("x-goog-api-key", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"请总结这段内容\"\n        }\n      ]\n    }\n  ]\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api-vip.apigo.ai/v1beta/models/{model}:generateContent")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"请总结这段内容\"\n        }\n      ]\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "这里是总结结果。"
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 24,
    "candidatesTokenCount": 36,
    "totalTokenCount": 60
  }
}
{
  "error": 123,
  "message": "<string>"
}
Gemini’s official docs use the same generateContent family for image understanding, image generation, and image editing.
  • Images can be passed as inlineData or via the Files API
  • Small assets are commonly sent inline, while larger or reusable assets are better handled through Files API references
  • This path is suitable for image QA, OCR-assisted analysis, UI understanding, and multimodal reasoning
  • Native image generation and image editing still use generateContent
  • Text and generated images both come back through candidates[].content.parts[]
  • Google’s official docs note that generated images include a SynthID watermark

Authorizations

x-goog-api-key
string
header
required

Path Parameters

model
string
required

Gemini model name.

Example:

"gemini-2.5-pro"

Body

application/json
contents
object[]
required
systemInstruction
object
generationConfig
object
safetySettings
object[]
tools
object[]

Response

Successful Gemini content response

candidates
object[]
usageMetadata
object