Skip to content

Generate Content

generateContent is the most commonly used generation endpoint in Gemini's native REST API, suitable for text Q&A, multi-turn chat, structured output, and multimodal understanding.

Endpoint

text
POST https://hboom.ai/v1beta/models/{model}:generateContent

Example models:

  • gemini-3-flash-preview
  • gemini-3-pro-preview
  • gemini-2.5-flash

Authentication

  • Google's native examples use x-goog-api-key: $GEMINI_API_KEY
  • When using the hboom relay, use the platform API key; examples below use the hboom gateway address

Minimal Request Example

bash
curl "https://hboom.ai/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "Authorization: Bearer sk-xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Explain how AI works in a few words"
          }
        ]
      }
    ]
  }'

Equivalent Google native request:

bash
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Explain how AI works in a few words"
          }
        ]
      }
    ]
  }'

Common Request Fields

FieldRequiredDescription
contentsYesArray of conversation content (at least one message)
contents[].roleNoRole: user or model
contents[].partsYesArray of message content parts
parts[].textNoText input
parts[].inlineDataNoBase64-encoded image, audio, video, etc.
parts[].fileDataNoReference to an uploaded file
system_instructionNoSystem prompt
generationConfigNoGeneration settings: temperature, output format, etc.
safetySettingsNoSafety filter config
toolsNoTool definitions, e.g. Google Search, function calling

Request Body Examples

Plain Text

json
{
  "contents": [
    {
      "parts": [
        {
          "text": "Explain how AI works in a few words"
        }
      ]
    }
  ]
}

With System Prompt

json
{
  "system_instruction": {
    "parts": [
      {
        "text": "You are a concise assistant."
      }
    ]
  },
  "contents": [
    {
      "parts": [
        {
          "text": "Explain how AI works in a few words"
        }
      ]
    }
  ]
}

With Generation Config

json
{
  "contents": [
    {
      "parts": [
        {
          "text": "Explain how AI works in a few words"
        }
      ]
    }
  ],
  "generationConfig": {
    "temperature": 0.7,
    "topP": 0.8,
    "topK": 20,
    "maxOutputTokens": 256,
    "responseMimeType": "text/plain"
  }
}

Multi-turn Conversation

json
{
  "contents": [
    {
      "role": "user",
      "parts": [{ "text": "Hello" }]
    },
    {
      "role": "model",
      "parts": [{ "text": "Great to meet you. What would you like to know?" }]
    },
    {
      "role": "user",
      "parts": [{ "text": "Explain how AI works in a few words" }]
    }
  ]
}

Response Example

json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "AI learns patterns from data and uses them to make predictions."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "avgLogprobs": -0.12
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 8,
    "candidatesTokenCount": 14,
    "totalTokenCount": 22
  },
  "modelVersion": "gemini-3-flash-preview"
}

Common Response Fields

FieldDescription
candidatesArray of candidate results
candidates[].content.parts[].textModel output text
candidates[].finishReasonStop reason, e.g. STOP
usageMetadataToken usage stats
modelVersionActual model version returned
promptFeedbackPrompt filter or block info

Streaming

For streaming output, use:

text
POST /v1beta/models/{model}:streamGenerateContent?alt=sse

Example:

bash
curl "https://hboom.ai/v1beta/models/gemini-3-flash-preview:streamGenerateContent?alt=sse" \
  -H "Authorization: Bearer sk-xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  --no-buffer \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Explain how AI works"
          }
        ]
      }
    ]
  }'

Use Cases

  • Text Q&A
  • Multi-turn chat
  • Image + text understanding
  • Audio, video, and PDF understanding with text output
  • JSON structured output
  • Tool calling and search augmentation

Notes

  • generateContent is a synchronous endpoint that returns the result immediately
  • For multimodal input (image, audio, video), the output is typically still text
  • For video generation, use Veo 3.1 Fast Video instead
  • For streaming text output, use streamGenerateContent

References

hboom AI