https://github.com/google-gemini/api-examples
Example code for the Gemini API
https://github.com/google-gemini/api-examples
Last synced: about 1 year ago
JSON representation
Example code for the Gemini API
- Host: GitHub
- URL: https://github.com/google-gemini/api-examples
- Owner: google-gemini
- License: apache-2.0
- Created: 2025-02-21T18:34:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-24T23:28:52.000Z (over 1 year ago)
- Last Synced: 2025-06-08T13:05:45.801Z (about 1 year ago)
- Language: Go
- Homepage: https://ai.google.dev/gemini-api/docs
- Size: 43 MB
- Stars: 52
- Watchers: 9
- Forks: 29
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://ai.google.dev/api) 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:
```python
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.