Skip to main content

Use Google Gemini with SmythOS

TL;DR
Add your Gemini API Key to Vault, configure an API Call component to POST to the Gemini endpoint, and handle the response.

Why Use Google Gemini With Your Agent?​

Google Gemini offers powerful text generation and content creation capabilities. By connecting it to SmythOS, you can:

  • Generate dynamic responses
  • Summarize or rephrase content
  • Build intelligent assistants
  • Inject LLM power into automated workflows

Prerequisites​

Before getting started:

Step-by-Step: Connect Gemini​

Step 1: Add Gemini API Key to Vault​

  1. Go to your Google AI Studio account
  2. Generate a new API Key
  3. In SmythOS, navigate to Vault → API Keys
  4. Add your Gemini API Key with a recognizable name (e.g., GEMINI_API_KEY)

Step 2: Configure API Call Component​

  1. Add an API Call component to your agent canvas
  2. Set the method to POST
  3. Use this URL:
https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent
  1. In Headers, include:
{
"Content-Type": "application/json",
"x-goog-api-key": "${GEMINI_API_KEY}"
}
  1. In the Body, insert:
{
"contents": [
{
"parts": [
{
"text": "Your prompt here"
}
]
}
]
}

Step 3: Define Inputs​

Example input payload:

{
"contents": [
{
"parts": [
{
"text": "Write a blog post about SmythOS integrations."
}
]
}
]
}
INFO
You can dynamically pass user inputs into the text field using mapped variables or prior component outputs.

Step 4: Use Outputs​

You’ll receive a JSON response with:

  • candidates[0].content.parts[0].text: The generated text
  • promptFeedback: Safety and model usage metadata

Use the Output Mapping to extract and reuse the result elsewhere in your workflow (e.g., in a Slack message, email, or UI element).

Step 5: Parse the Response​

The response contains a candidates array. Add a Code component to:

  • Extract the generated content
  • Handle errors or retries
  • Use the response in follow-up actions or UI updates
INFO
You can log outputs using Agent Logs for monitoring and debugging.

What’s Next?​

  • Try combining Gemini with Slack or Discord for interactive bots
  • Deploy your Gemini agent via Deploy as API
  • Log all completions in Agent Logs
  • Chain with multiple LLMs for content ranking or decision making
Use Google Gemini with SmythOS to generate responses, summarize data, or co-write content.