Skip to content

google-gemini/api-examples

Folders and files

NameName
Last commit message
Last commit date
Apr 24, 2025
Apr 22, 2025
Apr 20, 2025
Apr 20, 2025
Mar 4, 2025
Mar 24, 2025
Feb 26, 2025
Feb 26, 2025
Mar 11, 2025

Repository files navigation

Gemini API examples

This repository contains example code for key features of the Gemini API. The repo is organized by programming language.

The examples are embedded in the Gemini API reference and other places in the developer documentation.

Each file is structured as a runnable test case, ensuring that examples are executable and functional. Each test demonstrates a single concept and contains special comments called region tags that demarcate the test scaffolding from the example code snippet. Here's a Python example:

def test_text_gen_text_only_prompt(self):
    # [START text_gen_text_only_prompt]
    from google import genai

    client = genai.Client()
    response = client.models.generate_content(
        model="gemini-2.0-flash", contents="Write a story about a magic backpack."
    )
    print(response.text)
    # [END text_gen_text_only_prompt]

The API reference can be configured to show the code between the region tags.

If you're contributing, please make sure that the code within region tags follows best practices for example code: clear, complete, and concise.

Releases

No releases published

Packages

No packages published

Contributors 6