Is there any limit on the number of items in generate_content.contents
(Text generation | Gemini API | Google AI for Developers)? What happen if the items included are not related to one another?
Hello @khteh ,
there is no restriction on the number of items in the list, but please be noted that all the items in the list contents will be tokenized so as long a the total tokens would be less than the model input limit your should be fine.
and to answer your question, if they are not related to each other, it can be of different types, example you can give prompt, text, binary data, base64 image data etc. all these would be part of the model input.
hope that answers your question.
Does it work with a combination of text (prompt), image, video and/or voice all in one API request?
yes, you can give a combination of text and video and voice in a single API call .
for better performance and results please use “files api” to upload these files and give the file objects as list items.
following is a code snippet that can help you understand.
myfile = client.files.upload(file="path/to/sample.mp3")
response = client.models.generate_content(
model="gemini-2.0-flash", contents=["Describe this audio clip", myfile]
)
for detailed docuemntaiton on files api, please check it out here: