VOOZH about

URL: https://thenewstack.io/exploring-the-api-of-googles-gemini-language-model/

⇱ Exploring the API of Google’s Gemini Language Model - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-03-04 10:24:42
Exploring the API of Google’s Gemini Language Model
tutorial,
API Management / Large Language Models

Exploring the API of Google’s Gemini Language Model

A deeper look into the parameters of Gemini's API, showing how to maximize effectiveness of generated content across various applications.
Mar 4th, 2024 10:24am by Janakiram MSV
👁 Featued image for: Exploring the API of Google’s Gemini Language Model
Photo by BoliviaInteligente on Unsplash.

Prompt engineering is a critical aspect of leveraging the Gemini API for generating tailored and effective outputs from the language model. This practice involves designing and refining prompts to guide the LLM toward generating the desired content, whether for creative writing, coding, data analysis or any other application where natural language generation can be applied. The success of prompt engineering hinges not just on the skillful crafting of the prompt itself, but also on understanding and optimizing the parameters provided by the Gemini API,  such as temperature, max_output_tokens, top_p and top_k.

The importance of these parameters in prompt engineering cannot be overstated, as they enable users to customize the model’s behavior to specific needs, ensuring that the generated content meets the desired standards of accuracy, relevance, creativity and coherence.

This article aims to explore the nuances of the parameters of the Gemini API, providing insights into how these parameters can be leveraged to maximize the effectiveness of generated content across various applications.

A Closer Look at the API Parameters

The Gemini API provides a suite of parameters to fine-tune the generation of text, allowing users to balance between creativity and accuracy effectively. Here’s an overview of the key parameters, along with their impacts on the creativity and accuracy of LLM responses.

The below code snippet provides the basic structure of the API call for both text generation and chat completion. Refer to the previous tutorial, “How to Get Started with Google’s Gemini Large Language Model,” for details on installing and configuring Python SDK for Vertex AI.

from google.cloud import aiplatform
import vertexai
from vertexai.preview.generative_models import GenerativeModel, Part

vertexai.init()
model = GenerativeModel("gemini-pro")

response = model.generate_content(“What's the meaning of life?”,
max_output_tokens=128,
temperature=0,
top_p=1,
top_k=5
)
print(response.text)

Max_output_tokens: This parameter sets the maximum length of the model’s response in terms of tokens, which can be roughly equated to words. It controls the verbosity of the output, with a higher limit allowing for longer, more detailed responses. The choice of this limit can affect the depth and comprehensiveness of the response, but doesn’t directly influence its creativity or accuracy​​.

Temperature: This parameter controls the randomness of the output. A higher temperature increases creativity by making less probable tokens more likely to be chosen, leading to more varied and unexpected outputs. Conversely, a lower temperature results in more predictable, conservative outputs. It’s a crucial parameter for controlling the balance between creativity and determinism in the model’s responses​​​​.

Top_p (nucleus sampling): This parameter, also known as nucleus sampling, controls the cumulated probability threshold for token selection, ensuring that only the most probable tokens (up to a specified cumulative probability) are considered. This allows for a dynamic balance between creativity and accuracy. A lower threshold (closer to 0) will make the model’s outputs more focused and less diverse, while a higher threshold increases the variety of tokens used, potentially making the output more creative but less predictable​​​​.

Top_k: This parameter limits the selection of the next token to the k most likely tokens. A lower value of k restricts the model to a narrower choice of words, leading to more predictable outputs, while a higher value allows for a wider selection of tokens, increasing the potential creativity of the output. However, setting it too high can detract from the relevance and accuracy of the content​​​​.

In comparison, temperature and top_p are more directly related to controlling the model’s creativity, with higher values for either leading to more novel and varied outputs. The top_k parameter offers a more granular control over the selection pool of next tokens, directly influencing the diversity and potential creativity of the output. The parameter max_output_tokens, while not directly affecting creativity, sets the scope of the response, affecting the model’s ability to develop ideas fully or provide detailed information.

Each of these parameters plays a significant role in tailoring the LLM’s output to specific needs, allowing users to fine-tune the balance between creativity and accuracy based on the task at hand. Adjusting these parameters can significantly influence the model’s performance, making it imperative to understand their effects thoroughly for optimal results.

Grounding and Function Calling Expand Gemini’s Ability

Gemini introduced advanced function calling capabilities, which allow developers to seamlessly integrate external tools and APIs into their AI-driven applications. This feature enables the model to interact with external data sources and services, thereby extending its utility and application scope far beyond what’s possible with standalone AI models. For example, by defining functions that the model can call based on the input it receives, developers can create more dynamic, responsive and useful AI applications. This could range from fetching real-time data from external APIs to processing and generating outputs based on complex external datasets.

The sophistication of Gemini’s function-calling mechanism is a testament to its design as a highly interactive and integrable AI model, ready to tackle a wide array of practical use cases​​. In the upcoming parts of this series, I will walk you through the steps of integrating real-time flight tracking API with Gemini through a function-calling technique.

Grounding is another technique that enhances Gemini’s ability to provide relevant and accurate information by incorporating context-specific data into its processing. This capability, often supported by semantic search and retrieval-augmented generation models, enables the LLM to access and use external knowledge bases effectively, making it more adept at answering queries with high precision.

Grounding provides the following benefits:

  • Reduced hallucinations: Grounding minimizes the occurrence of model hallucinations by preventing the generation of non-factual content.
  • Anchored responses: Grounding ensures that model responses are firmly anchored to specific information, enhancing their relevance and reliability.
  • Enhanced trustworthiness and applicability: Grounded content is more trustworthy and practically applicable, leading to improved user satisfaction and confidence in the generated output.

Google has integrated Vertex AI Search with Gemini to provide grounding capabilities to the LLM. Similar to function calling, the model can be pointed to the data store index within Search to retrieve context information.

The Gemini API, with its customizable parameters — such as temperature, max_output_tokens, top_p, and top_k — offers unparalleled flexibility in tailoring AI-generated content to specific needs, balancing creativity and accuracy effectively.

Additionally, Gemini’s grounding and function-calling capabilities significantly expand its utility, enabling it to integrate external data sources and services seamlessly into its responses. These features collectively enhance Gemini’s ability to deliver contextually relevant, accurate and highly interactive AI applications across a wide range of domains.

TRENDING STORIES
Janakiram MSV (Jani) is a practicing architect, research analyst, and advisor to Silicon Valley startups. He focuses on the convergence of modern infrastructure powered by cloud-native technology and machine intelligence driven by generative AI. Before becoming an entrepreneur, he spent...
Read more from Janakiram MSV
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.