๐Ÿ“ฆ google-gemini / api-examples

Example code for the Gemini API

โ˜… 114 stars โ‘‚ 50 forks ๐Ÿ‘ 114 watching โš–๏ธ Apache License 2.0
๐Ÿ“ฅ Clone https://github.com/google-gemini/api-examples.git
HTTPS git clone https://github.com/google-gemini/api-examples.git
SSH git clone git@github.com:google-gemini/api-examples.git
CLI gh repo clone google-gemini/api-examples
Mark McDonald Mark McDonald Merge pull request #92 from markmcd/maps-grnd 856e8a0 3 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ go
๐Ÿ“ java
๐Ÿ“ javascript
๐Ÿ“ python
๐Ÿ“ rest
๐Ÿ“ third_party
๐Ÿ“„ .gitignore
๐Ÿ“„ CONTRIBUTING.md
๐Ÿ“„ LICENSE
๐Ÿ“„ README.md
๐Ÿ“„ README.md

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.