Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Google Gemini API image generation app samples

These are the code samples from the 5th post in the Gemini API series. More information about the scripts will be found there.

❗ API key required
An API key is required to use the Gemini API. Follow the instructions below. The app will not run without being added to the GEMINI_API_KEY environment variable or saved to a local file, .env (Node.js) or settings.py (Python).

Google AI code samples

App Description
gem20-image.js CommonJS Node.js script
gem20-image.mjs ECMAscript Node.js module
package.json NPM packages file
gem20-image.py Python 3 script
requirements.txt pip requirements file

Instructions

Node.js

  1. Ensure your Node (and NPM) installation is up-to-date (recommend 18+)
  2. Install packages: npm i
  3. Create API key and either save to .env file as GEMINI_API_KEY = <YOUR_API_KEY>; or to GEMINI_API_KEY environment variable.
  4. Run node gem20-image.js or node gem20-image.mjs

Python

  1. Ensure your Python (and pip) installation is up-to-date (recommend 3.9+)
  2. (optional) Create & activate a virtual environment ("virtualenv") for isolation
    • python3 -m venv myenv; source myenv/bin/activate
  3. (optional) Update pip and install uv: pip install -U pip uv
  4. Install packages:
    • pip install -Ur requirements.txt (or pip3)
    • (optional) If using uv: uv pip install -Ur requirements.txt
  5. Create API key and either save to settings.py file as GEMINI_API_KEY = 'YOUR_API_KEY' or to GEMINI_API_KEY environment variable.
  6. Run python gem20-image.py (or python3)
📝 Gemini API also accessible from GCP Vertex AI
While these sample scripts access the Gemini API from Google AI, a great place for beginners and those experimenting with it, the API is also accessible from GCP's Vertex AI platform for those ready to use Gemini in production workloads.