Generate content

Send content as parts. Receive a model candidate with text or function calls.

POST/google/v1beta/models/gemini-3.8-flash:generateContent

Generate content

The model is part of the URL. Use your Google key in x-goog-api-key. Send user input as a content object with text parts.

curl · whole response

curl "https://proxy.litechat.ai/google/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: $BUILD_GOOGLE_KEY" \
  -H "Content-Type: application/json" \
  --data '{
    "contents": [{"role": "user", "parts": [{"text": "Say hello in one sentence."}]}],
    "generationConfig": {
      "maxOutputTokens": 128,
      "thinkingConfig": {"thinkingBudget": 0}
    }
  }'

Read the candidate

Inspect candidates[].content.parts. A part with text contains text; other parts can contain function calls. The Python SDK offers response.text as a convenience accessor. REST uses the nested parts shown here.

Illustrative whole response

{
  "candidates": [{
    "index": 0,
    "content": {"role": "model", "parts": [{"text": "Hello! How can I help?"}]},
    "finishReason": "STOP"
  }],
  "usageMetadata": {"promptTokenCount": 12, "candidatesTokenCount": 8, "totalTokenCount": 20},
  "modelVersion": "gemini-3.8-flash"
}

Text and token counts are illustrative. STOP marks a normal stop, MAX_TOKENS marks truncation, and SAFETY marks filtered output. A function-call part requires a backend action.

Common parameters

contents
Use user and model roles with arrays of parts. Include earlier turns to continue the conversation. Use systemInstruction for system instructions.
generationConfig
Set maxOutputTokens for the output limit. Only one candidate is supported. Set thinkingConfig.thinkingBudget to 0 to disable thinking; use thinkingLevel to select reasoning effort. Other numeric budgets are unsupported.
responseJsonSchema
Set this under generationConfig, with responseMimeType: "application/json". The complete result is validated before output is sent. Use local schema references. Schema conversion cannot be combined with stop sequences or log probability controls.
functionCall and thoughtSignature
Function calls carry complete argument objects. Tool streams wait for the complete result. Return function results with the same call IDs and preserve thought signatures without modification. Signatures are scoped to your account/provider and expire after 24 hours.

Streaming

Keep the body and headers above; replace :generateContent in the URL with :streamGenerateContent?alt=sse and add --no-buffer to curl. SSE data contains candidate parts, finish information, or usage. Usage events can omit candidates. Read through the stream ending and handle later errors; a finish reason alone is not enough. There is no [DONE] sentinel.

See the Gemini streamGenerateContent reference.

← Getting startedBack to top ↑