https://github.com/google-gemini/gemini-api-quickstart
Get up and running with the Gemini API in under 5 minutes (with Python)
https://github.com/google-gemini/gemini-api-quickstart
gemini gemini-api
Last synced: 6 months ago
JSON representation
Get up and running with the Gemini API in under 5 minutes (with Python)
- Host: GitHub
- URL: https://github.com/google-gemini/gemini-api-quickstart
- Owner: google-gemini
- License: apache-2.0
- Created: 2024-09-06T20:13:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-23T14:40:24.000Z (about 1 year ago)
- Last Synced: 2024-12-23T15:33:58.060Z (about 1 year ago)
- Topics: gemini, gemini-api
- Language: CSS
- Homepage: https://ai.google.dev/gemini-api/docs/quickstart
- Size: 142 KB
- Stars: 293
- Watchers: 2
- Forks: 41
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gemini API Quickstart - Python
This repository contains a simple Python Flask App running with the Google AI Gemini API, designed to get you started building with Gemini's multi-modal capabilities. The app comes with a basic UI and a Flask backend.

## Basic request
To send your first API request with the [Google Gen AI SDK](https://ai.google.dev/gemini-api/docs/libraries#python), make sure you have the right dependencies installed (see installation steps below) and then run the following code:
```python
from google import genai
client = genai.Client(api_key="GEMINI_API_KEY")
chat = client.chats.create(model="gemini-2.0-flash")
response = chat.send_message("Hello world!")
print(response.text)
response = chat.send_message("Explain to me how AI works")
print(response.text)
for message in chat.get_history():
print(f'role - {message.role}',end=": ")
print(message.parts[0].text)
```
## Setup
1. If you don’t have Python installed, install it [from Python.org](https://www.python.org/downloads/).
2. [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) this repository.
3. Create a new virtual environment:
- macOS:
```bash
$ python -m venv venv
$ . venv/bin/activate
```
- Windows:
```cmd
> python -m venv venv
> .\venv\Scripts\activate
```
- Linux:
```bash
$ python -m venv venv
$ source venv/bin/activate
```
4. Install the requirements:
```bash
$ pip install -r requirements.txt
```
5. Make a copy of the example environment variables file:
```bash
$ cp .env.example .env
```
6. Add your [API key](https://ai.google.dev/gemini-api/docs/api-key) to the newly created `.env` file or as an environment variable.
7. Run the app:
```bash
$ flask run
```
You should now be able to access the app from your browser at the following URL: [http://localhost:5000](http://localhost:5000)!