Write Your First AI Script With Gemini API in Python

Enver Şanlı
2 min readSep 26, 2024

--

Every day, we hear about advancements in AI technologies, and it’s clear that the field is growing rapidly. Many companies are investing in AI-based solutions and training their employees to use AI effectively.

Additionally, AI is revolutionizing app development, with new ideas and projects leveraging AI to enhance user experience and engagement. Given the rapid pace of AI development, it’s crucial to stay updated and adapt these technologies to remain competitive.

I’ll demonstrate how to write a basic AI script using Python, which you can then integrate into your projects or ideas.

Gemini Api

Gemini is providing a free limited api for developers. Which is also very nice to have this opportunity because for the learning purpose, it would save money and time as wel but of course Gemini also has paid api. If you want to learn about prices, please click here.

Gemini offers a free, limited API for developers, which is a great opportunity for learning purposes as it can save time and money. However, Gemini also has a paid API for those with more extensive needs. For pricing information, please visit [Gemini Pricing]

First AI Script with Gemini

To utilize the Gemini API, you’ll need to install the google-generativeai package. Ensure that Python and pip are already installed on your system. Once these prerequisites are met, you can proceed with the installation process.

pip3 install -q -U google-generativeai

Open your terminal and execute the above command to install the google-generativeai package:

Once installed, you can import it into your Python script.

To use the Gemini API, you’ll need an API key. You can generate one by visiting the following link:

Generating an API key for Gemini should only take a few minutes. Once you have your key, you’re ready to start writing your first AI script!

Here’s a basic Python example using the Gemini API:


import google.generativeai as genai
import os
genai.configure(api_key="YourApiKey")
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("Write a song in turkish language.")
print(response.text)

As demonstrated above, it’s straightforward to write a basic AI script using the Gemini API. In just 15 minutes, you’ve gained the foundational knowledge to start experimenting.

Now, it’s time to enhance your ideas and skills. You can develop various applications, try them out for free, and harness the power of AI.

Thank you for reading! I hope this content has been valuable.

Enver ŞANLI

Software Engineer & Social Thinker

--

--

Enver Şanlı
Enver Şanlı

No responses yet