Google AI
ai.google.dev › gemini api › generating content
Generating content | Gemini API | Google AI for Developers
May 20, 2026 - Client client = new Client(); GenerateContentResponse response = client.models.generateContent( "gemini-3.5-flash", "Write a story about a magic backpack.", null); System.out.println(response.text()); ... from google import genai import PIL.Image client = genai.Client() organ = PIL.Image.open(media / "organ.jpg") response = client.models.generate_content( model="gemini-3.5-flash", contents=["Tell me about this instrument", organ] ) print(response.text)
GitHub
googleapis.github.io › js-genai › release_docs › classes › models.Models.html
Models | @google/genai
The response from generating content. const response = await ai.models.generateContent({ model: 'gemini-2.0-flash', contents: 'why is the sky blue?', config: { candidateCount: 2, } }); console.log(response); Copy
Videos
Google
docs.cloud.google.com › gemini enterprise agent platform › generate content with the gemini api
Generate content with the Gemini API | Gemini Enterprise Agent Platform | Google Cloud Documentation
April 29, 2026 - Use generateContent or streamGenerateContent to generate content with Gemini. The Gemini model family includes models that work with multimodal prompt requests. The term multimodal indicates that you can use more than one modality, or type of ...
Google
docs.cloud.google.com › gemini enterprise agent platform › method: models.generatecontent
Method: models.generateContent | Gemini Enterprise Agent Platform | Google Cloud Documentation
May 5, 2026 - Generate content with multimodal inputs. ... Where {service-endpoint} is one of the supported service endpoints. ... Required. The fully qualified name of the publisher model or tuned model endpoint to use.
Medium
medium.com › @jelkhoury880 › gemini-pro-api-quick-hands-on-ba38b4d8a681
Gemini pro API quick hands-on. This article is a just a hands-on code… | by Joe El Khoury | Medium
July 26, 2024 - This part is similar to the previous content generation but uses a streaming approach (`stream=True`). This might be useful for handling larger responses or real-time data streaming. It iterates over the chunks of the response, printing each chunk followed by a line of underscores for separation. import google.generativeai as genai import os genai.configure(api_key=os.getenv('GEMINI_API_KEY') or "YOUR KEY HERE") # will list available models for m in genai.list_models(): if 'generateContent' in m.supported_generation_methods: print(m.name) model = genai.GenerativeModel('gemini-pro') response =model.generate_content("What is the future of AI in one sentence?") print(response.text) print(response.prompt_feedback) print(response.candidates) response = model.generate_content("What is the future of AI in one sentence?", stream=True) for chunk in response: print(chunk.text) print("_"*80)
Google AI
ai.google.dev › gemini-api › docs › text-generation
Gemini API | Google AI for Developers
1 week ago - Note: If the model uses "thinking" or tools, you must preserve and resend all model-generated steps (such as thought and function_call steps) exactly as received, as they contain signatures required to continue the conversation. from google import genai client = genai.Client() history = [ { "type": "user_input", "content": [{"type": "text", "text": "I have 2 dogs in my house."}] } ] interaction1 = client.interactions.create( model="gemini-3.5-flash", store=False, input=history ) print("Response 1:", interaction1.steps[-1].content[0].text) for step in interaction1.steps: history.append(step.model_dump()) history.append({ "type": "user_input", "content": [{"type": "text", "text": "How many paws are in my house?"}] }) interaction2 = client.interactions.create( model="gemini-3.5-flash", store=False, input=history ) print("Response 2:", interaction2.steps[-1].content[0].text)
Firebase
firebase.google.com › documentation › firebase ai logic › generate text using the gemini api
Generate text using the Gemini API | Firebase AI Logic
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()) .generativeModel("gemini-3.5-flash"); // Use the GenerativeModelFutures Java compatibility layer which offers // support for ListenableFuture and Publisher APIs GenerativeModelFutures model = GenerativeModelFutures.from(ai); // Provide a prompt that contains text Content prompt = new Content.Builder() .addText("Write a story about a magic backpack.") .build(); // To generate text output, call generateContent with the text input ListenableFuture<GenerateContentResponse> response = model.generateContent(prompt); Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() { @Override public void onSuccess(GenerateContentResponse result) { String resultText = result.getText(); System.out.println(resultText); } @Override public void onFailure(Throwable t) { t.printStackTrace(); } }, executor);
GitHub
googleapis.github.io › python-genai
Google Gen AI SDK documentation
from google.genai import types response = client.models.generate_content( model='gemini-2.0-flash-001', contents='high', config=types.GenerateContentConfig( system_instruction='I say high, you say low', max_output_tokens=3, temperature=0.3, ), ) print(response.text)
Google AI
ai.google.dev › generate content api › gemini 3 developer guide
Gemini 3 Developer Guide | Gemini Generate Content API (Legacy) | Google AI for Developers
1 week ago - Explore our collection of Gemini 3 apps to see how the model handles advanced reasoning, autonomous coding, and complex multimodal tasks. Get started with a few lines of code: from google import genai client = genai.Client() response = client.models.generate_content( model="gemini-3.1-pro-preview", contents="Find the race condition in this multi-threaded C++ snippet: [code here]", ) print(response.text) import { GoogleGenAI } from "@google/genai"; const ai = new GoogleGenAI({}); async function run() { const response = await ai.models.generateContent({ model: "gemini-3.1-pro-preview", contents:
GitHub
github.com › google-gemini › deprecated-generative-ai-python › blob › main › docs › api › google › generativeai › GenerativeModel.md
deprecated-generative-ai-python/docs/api/google/generativeai/GenerativeModel.md at main · google-gemini/deprecated-generative-ai-python
This GenerativeModel.generate_content method can handle multimodal input, and multi-turn conversations. >>> model = genai.GenerativeModel('models/gemini-1.5-flash') >>> response = model.generate_content('Tell me a story about a magic backpack') >>> response.text ·
Author google-gemini
Google Cloud
cloud.google.com › vertex ai › generative ai on vertex ai › generate content with function calls
Generate content with function calls | Generative AI on Vertex AI | Google Cloud Documentation
using Google.Cloud.AIPlatform.V1; using System; using System.Threading.Tasks; using Type = Google.Cloud.AIPlatform.V1.Type; using Value = Google.Protobuf.WellKnownTypes.Value; public class FunctionCalling { public async Task<string> GenerateFunctionCall( string projectId = "your-project-id", string location = "us-central1", string publisher = "google", string model = "gemini-2.0-flash-001") { var predictionServiceClient = new PredictionServiceClientBuilder { Endpoint = $"{location}-aiplatform.googleapis.com" }.Build(); // Define the user's prompt in a Content object that we can reuse in // model calls var userPromptContent = new Content { Role = "USER", Parts = { new Part { Text = "What is the weather like in Boston?"
Patloeber
patloeber.com › gemini-multimodal
Get started with Gemini's multimodal capabilities | Patrick Loeber
February 17, 2025 - from google.genai import types with open('sample.mp3', 'rb') as f: image_bytes = f.read() response = client.models.generate_content( model='gemini-2.0-flash', contents=[ 'Describe this audio clip', types.Part.from_bytes(data=image_bytes, mime_type='audio/mp3') ] ) print(response.text)
GitHub
github.com › GoogleCloudPlatform › generative-ai › blob › main › gemini › getting-started › intro_gemini_curl.ipynb
generative-ai/gemini/getting-started/intro_gemini_curl.ipynb at main · GoogleCloudPlatform/generative-ai
"The `generateContent` method can handle a wide variety of use cases, including multi-turn chat and multimodal input, depending on what the underlying model supports. In this example, you send a text prompt and request the model response in text."
Author GoogleCloudPlatform
Top answer 1 of 4
6
For anyone (or bot) that arrives here looking for how to set a timeout when using the modern-as-of-late-2024 Google GenAI SDK that can also use the Vertex API (more info at the repository), setting a timeout using HttpOptions works.
Here is an example with a 30-second timeout:
from google import genai
from google.genai import types
client = genai.Client(
http_options=types.HttpOptions(timeout=30_000) # timeout is in milliseconds
)
response = client.models.generate_content(
model='gemini-2.5-flash', contents='Why is the sky blue?'
)
print(response.text)
2 of 4
3
If you would use the async version of generate_content, you can utilize the native Python's asyncio function wait_for. If a timeout occurs, it cancels the task and raises TimeoutError. The script could look like:
import asyncio
model = GenerativeModel('gemini-pro')
timeout = 5 # seconds
try:
response = await asyncio.wait_for(
model.generate_content_async("Pick a number"),
timeout=timeout,
)
except asyncio.exceptions.TimeoutError:
pass
Google AI
ai.google.dev › gemini api › gemini api reference
Gemini API reference | Google AI for Developers
May 30, 2024 - curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash: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" } ] } ] }'