Gemini Pro API in Python: Learn to Access using Google API Key

Mervin Praison · Beginner ·🧠 Large Language Models ·2y ago

Key Takeaways

Accessing Gemini API using API keys generated from Google AI Studio and Google Cloud Console, and integrating Gemini into a Python application using the Google Generative AI package.

Full Transcript

this is amazing what if you can use Gemini API using API Keys generated from Google AI Studio what if you can use generative AI package to interact with your Gemini API what is the difference between Google AI Studio vertex AI API keys and service account that's exactly what we're going to see today let's get [Music] started hi everyone I'm really excited to show you about gerini AP using API key and also we are going to see the difference between vertex Ai and Google AI Studio I'm going to take you through step by step but before that I regularly create videos in regards to Artificial Intelligence on my YouTube channel so do subscribe and click the Bell icon to stay tuned coming to Gemini API there are two ways of accessing this API One is using Google Cloud console another one is using Google AI Studio Google Cloud console looks like this and here you can create your service account from the I am and admin panel either you grant access to the existing email address or you can create a service account on the left hand side by clicking this icon service account is nothing but email address for our software to use so that is all about Google Cloud console and we use vertex AI python package to interact with API but in regards to Google AI Studio we use Google generative AI python package to interact with the API and we generate API key from Google AI Studio to use Gemini API so Google AI Studio looks like this and you can create your API Key by clicking this button keep a copy of the API key that is required to run the current application which we are going to create now let's dive into the code the first step is cond create iph and gerini python equal 3.11 and click enter then cond activate gerini and click enter next export your Google API key which you have just generated from Google AI Studio here and then click enter next pip install Google generative AI package this is the one used to interact with gini API now let's create a file called app.py and open it inside the file import google. generative AI as gen aai then UT OS the first step is the configuration where you pass your API key to gen ai. configure then you define the temperature top P top K and then Max output tokens the second step is initializing the model here gen. generative model we are defining the model name and passing the generation config and the third step is to generate content that means ask questions to the large language model to do that response equals model. generate content and I'm asking a question create a meal plan for today and finally you're printing out the response so this is similar to vertex AI API which I've shown before which I will link that in the description below in this we are importing generative AI package defining the configuration initializing the model using gen. generative model and then ask you to generate content by asking a question now we're going to run this code in your terminal Python app.py and click enter now we got breakfast lunch dinner snacks and other tips now we're going to see how we can stream this response to do that I'm adding Chunk in response and then printing the output now going to delete this line now going back to our terminal Python app.py and click enter now it's going to stream it streamed very quickly that you couldn't see the streamed response now we are going to use gini Vision API so we're going to change the model name to gini Pro Vision then we are going to import the path from path lib next we are going to change the output is print response. txt the configurations remain the same in the generate content step we are going to import image image path equals path image. jpeg next we are reading bytes from that image next we're going to create prompt Parts which contains the question to ask about the image and the image so the question we going to ask is describe what the people are doing in this image so this is the image and we going to describe what the people are doing and finally response equals model. generate content and passing the prompts it's multimodal so it can accept text and image and finally printing the response now we're going to run this code in your terminal Python app.py and click enter here is the answer two men are playing Cricket the man in the foreground is the batsman and the Man in the background is the Wicket keeper the batsman is about to hit the ball with this bat the Wicket keeper is standing behind the stumps and ready to catch the ball if the batsman misses it that's it as simple simple as that now you are able to integrate Gemini into your own python application I'm going to create more videos similar to this so stay tuned I hope you like this video do like share and subscribe and thanks for watching

Original Description

🚀 In this comprehensive tutorial, we delve into the exciting world of the Gemini API and how to use it with API keys generated from Google AI Studio. Whether you're a beginner or an advanced user, this video is tailored to provide you with a clear understanding of the interaction between generative AI packages and the Gemini API. We compare Google AI Studio and Vertex AI, exploring their differences in API keys and service accounts. 👩‍💻 Starting with an introduction to the Gemini API and its access methods, we guide you through creating service accounts in Google Cloud Console, and utilizing Python packages for effective API interaction. Our step-by-step process includes detailed instructions on setting up your environment, generating API keys, and writing Python code to interact with the API. Gemini Playlist: https://www.youtube.com/playlist?list=PLYQsp-tXX9w63Xe06j_gevoVTQ2ArybB6 Gemini Pro Beginners: https://www.youtube.com/watch?v=mkFDhoQZC3U Gemini Pro API: https://www.youtube.com/watch?v=V3vjwwIvB0I Gemini Pro Vision API: https://www.youtube.com/watch?v=sI7VsMzDfms Gemini Pro Function Calling: https://www.youtube.com/watch?v=iBxB_enzjks Learn to Use Google Gemini/Bard: https://www.youtube.com/watch?v=FFclp3sfKEc 🔍 Timestamps: 0:00 - Introduction to Gemini API and Google AI Studio 0:33 - Service Accounts and Google Cloud Console Overview 1:19 - Using Vertex AI Python Package 1:29 - Generating API Keys in Google AI Studio 1:53 - Step-by-Step Coding Tutorial 3:00 - Comparing Google AI Studio and Vertex AI 3:47 - Advanced Application: Gemini Vision API 💡 Stay tuned till the end for a practical demonstration of integrating Gemini API into a Python application, including a unique example using the Gemini Vision API. 👍 If you find this tutorial helpful, please like, share, and subscribe for more AI-related content. Your support helps us create more informative and useful videos! #GeminiAPI #Python #APIKEY #GoogleGemini #GoogleGeminiAI #Gemini #AI #GoogleB
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Mervin Praison · Mervin Praison · 0 of 60

← Previous Next →
1 Build GCP Infra using Pulumi in YAML format
Build GCP Infra using Pulumi in YAML format
Mervin Praison
2 How to Convert a Pulumi YAML File to Python Format
How to Convert a Pulumi YAML File to Python Format
Mervin Praison
3 Speed Up AWS EKS: A Complete Guide to Performance Tuning & Debugging!
Speed Up AWS EKS: A Complete Guide to Performance Tuning & Debugging!
Mervin Praison
4 Learn GCP GKE to AWS EKS Migration in Just 5 Minutes: Quick Guide
Learn GCP GKE to AWS EKS Migration in Just 5 Minutes: Quick Guide
Mervin Praison
5 AWS & Kubernetes: The Definitive Guide to Data Persistence with PV and PVC
AWS & Kubernetes: The Definitive Guide to Data Persistence with PV and PVC
Mervin Praison
6 ChatGPT Voice Conversation RELEASED! It's AMAZING!! (Demo)
ChatGPT Voice Conversation RELEASED! It's AMAZING!! (Demo)
Mervin Praison
7 How to Install Mistral 7B in Minutes: Quick & Easy Guide! ✅
How to Install Mistral 7B in Minutes: Quick & Easy Guide! ✅
Mervin Praison
8 Code Llama Install Locally: 🐍💻 Elevate Your Python Skills!
Code Llama Install Locally: 🐍💻 Elevate Your Python Skills!
Mervin Praison
9 Orca Mini: Your Ultimate Guide to Install and Test on Mac & Linux 💻
Orca Mini: Your Ultimate Guide to Install and Test on Mac & Linux 💻
Mervin Praison
10 Quick & Easy Vicuna Setup on Mac and Linux 💻
Quick & Easy Vicuna Setup on Mac and Linux 💻
Mervin Praison
11 Quick Guide: Llama2 Local Installation and ChatGPT with pip! Python🛠️
Quick Guide: Llama2 Local Installation and ChatGPT with pip! Python🛠️
Mervin Praison
12 Query PDFs Like a Pro with Local GPT: Full Setup Guide! 📜
Query PDFs Like a Pro with Local GPT: Full Setup Guide! 📜
Mervin Praison
13 LM Studio: EASIEST way to Run Large Language Models Locally!
LM Studio: EASIEST way to Run Large Language Models Locally!
Mervin Praison
14 AMAZING ChatGPT Vision is OUT! 🤯 14+ Examples (Step-by-Step) FULL Tutorial
AMAZING ChatGPT Vision is OUT! 🤯 14+ Examples (Step-by-Step) FULL Tutorial
Mervin Praison
15 Unbelievable! Build ANY App Instantly with Smol AI! 😲🔥
Unbelievable! Build ANY App Instantly with Smol AI! 😲🔥
Mervin Praison
16 Amazing! AutoGen Made Easy: A Step-by-Step Beginners Guide 📚
Amazing! AutoGen Made Easy: A Step-by-Step Beginners Guide 📚
Mervin Praison
17 How to Set Up LoLLMS and Run LLMs Locally! 🚀 Step-by-Step Tutorial
How to Set Up LoLLMS and Run LLMs Locally! 🚀 Step-by-Step Tutorial
Mervin Praison
18 GPT4All: INSANE Way to Run Large Language Models Locally! 😲 Step-By-Step Tutorial
GPT4All: INSANE Way to Run Large Language Models Locally! 😲 Step-By-Step Tutorial
Mervin Praison
19 Incredible AI-Powered NPCs in Unity Game Engine: Step by Step Tutorial!🤯
Incredible AI-Powered NPCs in Unity Game Engine: Step by Step Tutorial!🤯
Mervin Praison
20 MemGPT 🧠 LLM as Operating System. It's INSANE! Step-by-Step Tutorial 🤯
MemGPT 🧠 LLM as Operating System. It's INSANE! Step-by-Step Tutorial 🤯
Mervin Praison
21 Text Generation Web UI: MIND-BLOWING Way to Run LLM Locally! 🤯
Text Generation Web UI: MIND-BLOWING Way to Run LLM Locally! 🤯
Mervin Praison
22 Unlock the INSANE Power of OpenAI GPT-4 with C#/.NET! 😲
Unlock the INSANE Power of OpenAI GPT-4 with C#/.NET! 😲
Mervin Praison
23 Integrate Langchain and Ollama for Local AI Power 🤯 Indeed POWERFUL!
Integrate Langchain and Ollama for Local AI Power 🤯 Indeed POWERFUL!
Mervin Praison
24 ChatDev: INSANE Virtual AI Agents! Future of Software Development 😲
ChatDev: INSANE Virtual AI Agents! Future of Software Development 😲
Mervin Praison
25 Query PDFs Using Mistral: Unlock INSANE Power! 🤯
Query PDFs Using Mistral: Unlock INSANE Power! 🤯
Mervin Praison
26 AutoGen + Open-Source LLMs: UNBELIEVABLE! Step-by-Step Tutorial You Can't Miss! 🤯
AutoGen + Open-Source LLMs: UNBELIEVABLE! Step-by-Step Tutorial You Can't Miss! 🤯
Mervin Praison
27 AutoGen + Text Generation WebUI: Unbelievable 100% Local Private Setup 🤯
AutoGen + Text Generation WebUI: Unbelievable 100% Local Private Setup 🤯
Mervin Praison
28 MemGPT: Amazing! External Context for LLM #ai #llm #memgpt  #generativeai #mem #gpt #openai #chatgpt
MemGPT: Amazing! External Context for LLM #ai #llm #memgpt #generativeai #mem #gpt #openai #chatgpt
Mervin Praison
29 GeniA: Kubernetes + AI for MIND-BLOWING Operational Efficiency! 🤯 FULL Tutorial
GeniA: Kubernetes + AI for MIND-BLOWING Operational Efficiency! 🤯 FULL Tutorial
Mervin Praison
30 VertexAI Meets LangChain for Mind-Blowing AI Conversations! 😲 Step by Step Tutorial
VertexAI Meets LangChain for Mind-Blowing AI Conversations! 😲 Step by Step Tutorial
Mervin Praison
31 Simplified ChatGPT API Setup on Node.js for Newbies! 😍 Step by Step Tutorial
Simplified ChatGPT API Setup on Node.js for Newbies! 😍 Step by Step Tutorial
Mervin Praison
32 Autogen: Ollama integration 🤯 Step by Step Tutorial. Mind-blowing!
Autogen: Ollama integration 🤯 Step by Step Tutorial. Mind-blowing!
Mervin Praison
33 LiteLLM: One-Function Call to ANY Large Language Model! 🤯 UNBELIEVABLE!
LiteLLM: One-Function Call to ANY Large Language Model! 🤯 UNBELIEVABLE!
Mervin Praison
34 ChatGPT Chatbot in Less Time Than You Think! 🚀😎 Step-by-Step Tutorial
ChatGPT Chatbot in Less Time Than You Think! 🚀😎 Step-by-Step Tutorial
Mervin Praison
35 LiteLLM Chatbot: Build Your Own in MINUTES! INSANE! 🤖🔥
LiteLLM Chatbot: Build Your Own in MINUTES! INSANE! 🤖🔥
Mervin Praison
36 Create Chatbot: Turn ANY Open-Source LLM into a Conversation Pro! 🤖
Create Chatbot: Turn ANY Open-Source LLM into a Conversation Pro! 🤖
Mervin Praison
37 Create Chatbot: Ollama Integration Made UNBELIEVABLY Easy! 🎉
Create Chatbot: Ollama Integration Made UNBELIEVABLY Easy! 🎉
Mervin Praison
38 LlamaIndex + ChatGPT: Ingest Data and Experience UNBELIEVABLE Query Results! 🌟
LlamaIndex + ChatGPT: Ingest Data and Experience UNBELIEVABLE Query Results! 🌟
Mervin Praison
39 INSANE! OpenAgents: Automated Data Analysis with Kaggle 🤯
INSANE! OpenAgents: Automated Data Analysis with Kaggle 🤯
Mervin Praison
40 React.js LLM Agent for Next-Gen Coding using ChatGPT 🚀 Mind-Blowing 🤯
React.js LLM Agent for Next-Gen Coding using ChatGPT 🚀 Mind-Blowing 🤯
Mervin Praison
41 MemGPT + Any LLM 🚀 100% Local & Private Integration Unveiled! Unlimited Memory
MemGPT + Any LLM 🚀 100% Local & Private Integration Unveiled! Unlimited Memory
Mervin Praison
42 MemGPT  + AutoGen 🧠🤖 Unlimited Memory & Autonomous AI Agents! INSANE🤯
MemGPT + AutoGen 🧠🤖 Unlimited Memory & Autonomous AI Agents! INSANE🤯
Mervin Praison
43 AutoGen + Google's Palm LLM & More! Revolutionary AI Integration 🚀
AutoGen + Google's Palm LLM & More! Revolutionary AI Integration 🚀
Mervin Praison
44 MemGPT & LM Studio Integration Revealed! 🔥 Next-Level AI
MemGPT & LM Studio Integration Revealed! 🔥 Next-Level AI
Mervin Praison
45 🚀 AutoLLM: Unlock the Power of 100+ Language Models! Step-by-Step Tutorial
🚀 AutoLLM: Unlock the Power of 100+ Language Models! Step-by-Step Tutorial
Mervin Praison
46 AutoLLM & Gradio Integration You Won't Believe! 🤯 Mind-Blowing
AutoLLM & Gradio Integration You Won't Believe! 🤯 Mind-Blowing
Mervin Praison
47 AutoLLM & FastAPI Tutorial: Query 100+ Language Models! 😱
AutoLLM & FastAPI Tutorial: Query 100+ Language Models! 😱
Mervin Praison
48 Quivr: LLM's Second Brain - Transforming Data Management & Advanced Query with AI! 🤯
Quivr: LLM's Second Brain - Transforming Data Management & Advanced Query with AI! 🤯
Mervin Praison
49 AutoGen & MemGPT with Local LLM: A Complete Setup Tutorial! 🧠 AMAZING 🤯
AutoGen & MemGPT with Local LLM: A Complete Setup Tutorial! 🧠 AMAZING 🤯
Mervin Praison
50 LocalAI: Free, Open Source OpenAI Alternative 🚀 INSANE 🤯 Step-by-Step Tutorial
LocalAI: Free, Open Source OpenAI Alternative 🚀 INSANE 🤯 Step-by-Step Tutorial
Mervin Praison
51 Yarn Mistral 7B 128k LARGE context window, Small size 🤯 INSANE 🚀 Setup Tutorial!
Yarn Mistral 7B 128k LARGE context window, Small size 🤯 INSANE 🚀 Setup Tutorial!
Mervin Praison
52 Zephyr-7B: The Small and Mighty LLM 🤯 Step by Step Tutorial! 📘
Zephyr-7B: The Small and Mighty LLM 🤯 Step by Step Tutorial! 📘
Mervin Praison
53 Promptfoo: How to Test Your LLM ? 🚀  VERY EASY!
Promptfoo: How to Test Your LLM ? 🚀 VERY EASY!
Mervin Praison
54 Pydantic: How to Validate LLM Responses? 🚀 Quality Response. VERY EASY!!!!
Pydantic: How to Validate LLM Responses? 🚀 Quality Response. VERY EASY!!!!
Mervin Praison
55 Pydantic: FORCE Your AI to Respond Back in UPPERCASE! 🤯 Step-by-Step Tutorial 🔥
Pydantic: FORCE Your AI to Respond Back in UPPERCASE! 🤯 Step-by-Step Tutorial 🔥
Mervin Praison
56 Pydantic: How to use LLM to convert unstructured data to structured data?
Pydantic: How to use LLM to convert unstructured data to structured data?
Mervin Praison
57 AutoGen Function Calling: INSANE 🚀 Custom Integrations! Step-by-Step Tutorial 🤯
AutoGen Function Calling: INSANE 🚀 Custom Integrations! Step-by-Step Tutorial 🤯
Mervin Praison
58 OpenAI Assistants API + Python 🤖 How to get started? (FULL Tutorial) 🤯 INSANE
OpenAI Assistants API + Python 🤖 How to get started? (FULL Tutorial) 🤯 INSANE
Mervin Praison
59 GPT-4 Vision API 🤯 INSANE Video Recognition Powers! Step-by-Step Tutorial 🚀
GPT-4 Vision API 🤯 INSANE Video Recognition Powers! Step-by-Step Tutorial 🚀
Mervin Praison
60 GPT-4 Vision API 🚀 The Future of Image Recognition! 🤯 Step-by-Step Tutorial
GPT-4 Vision API 🚀 The Future of Image Recognition! 🤯 Step-by-Step Tutorial
Mervin Praison

This video teaches how to access Gemini API using API keys generated from Google AI Studio and Google Cloud Console, and how to integrate Gemini into a Python application using the Google Generative AI package. The video covers the difference between Vertex AI and Google AI Studio, and how to use the Google Generative AI package to interact with the Gemini API.

Key Takeaways
  1. Create a service account in Google Cloud Console
  2. Generate an API key from Google AI Studio
  3. Install the Google Generative AI package
  4. Create a Python application using the Google Generative AI package
  5. Configure the API key and model settings
  6. Initialize the model and generate content
  7. Stream the response
  8. Use the Gemini Vision API to generate content from an image
💡 The Google Generative AI package can be used to interact with the Gemini API, and the API key generated from Google AI Studio is required to run the application.

Related AI Lessons

The 2026 AI Model Release Race: Every Major LLM Launch You Need to Know
Stay updated on the 2026 AI model release race, including major LLM launches like Claude Sonnet 5 and GPT-5.6, to leverage the latest advancements in AI technology
Dev.to AI
Call GPT, Claude, and Gemini from one API key — a 3-step setup
Access GPT, Claude, and Gemini through one API key with a 3-step setup using Modelishub
Dev.to AI
Your LLM Doesn’t Pick Stocks — It Remembers Them
Discover how LLMs remember stock picks rather than making actual predictions, and why this matters for AI-driven investment strategies
Medium · Machine Learning
Word Representation
Learn how word representation works in NLP and its importance in understanding human language, enabling applications like text classification and language translation
Medium · NLP

Chapters (7)

Introduction to Gemini API and Google AI Studio
0:33 Service Accounts and Google Cloud Console Overview
1:19 Using Vertex AI Python Package
1:29 Generating API Keys in Google AI Studio
1:53 Step-by-Step Coding Tutorial
3:00 Comparing Google AI Studio and Vertex AI
3:47 Advanced Application: Gemini Vision API
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →