← Back to API List

Generate Content with Gemini Flash

POST/v1beta/models/gemini-2.5-flash-preview-04-17:generateContentGoogle AI

The Gemini Flash model is Google's fastest and most cost-effective multimodal model. It's optimized for high-volume, fast-response scenarios such as summarization, chat applications, image and video captioning, and data extraction from documents and tables. It supports text, image, and audio input, and generates text output.

text generationgeminiflashmultimodalfast
Official Documentation

Headers

Content-TypestringRequired

Set to `application/json`.

X-Goog-Api-KeystringRequired

Your Google AI API key.

Request Body

contentsarray of objectRequired

An array of Content objects. Each Content object contains a list of Parts.

safetySettingsarray of object

A list of unique SafetySetting instances for blocking unsafe content.

generationConfigobject

Configuration options for model generation and outputs.

Response Body

candidatesarray of object

A list of generated candidate responses from the model.

promptFeedbackobject

Feedback regarding the safety of the prompt.

Code Examples

cURL

cURL
curl 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-04-17:generateContent?key=YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[{"text": "Explain quantum computing in simple terms."}]
      }],
      "generationConfig": {
        "temperature": 0.7,
        "maxOutputTokens": 150
      }
    }'

Node.js

JavaScript
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash-preview-04-17",
    contents: "Explain quantum computing in simple terms.",
    config: {
      temperature: 0.7,
      maxOutputTokens: 150
    }
  });
  console.log(response.text);
}

run();

Python

Python
import google.generativeai as genai

genai.configure(api_key="YOUR_API_KEY")

model = genai.GenerativeModel('gemini-2.5-flash-preview-04-17')
response = model.generate_content(
    "Explain quantum computing in simple terms.",
    generation_config=genai.types.GenerationConfig(
        temperature=0.7,
        max_output_tokens=150
    )
)
print(response.text)

Example Response

JSON

JSON
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Imagine a regular computer uses bits, which are like light switches that are either ON (1) or OFF (0). Quantum computers use 'qubits'. A qubit is like a dimmer switch that can be ON, OFF, or somewhere in between. It can even be both ON and OFF at the same time (superposition)!\\n\\nThis 'quantum weirdness' allows quantum computers to do many calculations at once, making them incredibly fast for certain problems that are too hard for regular computers, like discovering new medicines or breaking complex codes."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "promptFeedback": {
    "safetyRatings": [
      {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_HARASSMENT",
        "probability": "NEGLIGIBLE"
      },
      {
        "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
        "probability": "NEGLIGIBLE"
      }
    ]
  }
}