Skip to main content
The Gemini endpoint generates contextual responses using Google’s Gemini 2.0 Flash model, incorporating both conversation transcripts and emotional analysis data.

Endpoint

POST http://localhost:5000/api/gemini

Request body

transcript
string
required
The conversation transcript text to analyze and respond to
emoData
object
Object containing emotion names as keys and confidence scores (0-1) as values. The top 3 emotions by score are used in the prompt.Example:
{
  "joy": 0.85,
  "contentment": 0.72,
  "interest": 0.68,
  "surprise": 0.45
}

Response

response
string
The AI-generated response text from Gemini
emotions
object
The emotion data that was provided in the request, echoed back in the response

Example request

curl -X POST http://localhost:5000/api/gemini \
  -H "Content-Type: application/json" \
  -d '{
    "transcript": "I had a really great day today. Everything went well at work.",
    "emoData": {
      "joy": 0.85,
      "contentment": 0.72,
      "interest": 0.68
    }
  }'

Example response

{
  "response": "That's wonderful to hear! It sounds like you had a very productive and fulfilling day.",
  "emotions": {
    "joy": 0.85,
    "contentment": 0.72,
    "interest": 0.68
  }
}

Error responses

error
string
Description of the error that occurred

Missing transcript (400)

{
  "error": "Transcript is required"
}

Server configuration error (500)

{
  "error": "Unable to process your request at this time"
}

Model configuration

The endpoint uses the following Gemini API parameters:
temperature
number
default:"0.3"
Controls randomness in the response (0.0-1.0). Lower values make output more deterministic.
topK
number
default:"20"
Limits the number of tokens considered at each step
topP
number
default:"0.8"
Nucleus sampling parameter for controlling diversity
maxOutputTokens
number
default:"100"
Maximum length of the generated response

Emotion processing

When emoData is provided:
  1. Emotions are sorted by score (highest to lowest)
  2. The top 3 emotions are selected
  3. Scores are converted to percentages with one decimal place
  4. Formatted as emotion: score% and included in the prompt
Example formatted emotion data:
joy: 85.0%
contentment: 72.0%
interest: 68.0%

Implementation details

The endpoint:
  1. Validates that transcript is provided
  2. Processes emotion data (if provided) to extract top 3 emotions
  3. Formats a prompt using the GEMINI_PROMPT environment variable template
  4. Sends the request to Gemini 2.0 Flash model
  5. Extracts and returns the generated text response
The endpoint requires GEMINI_API_KEY and GEMINI_PROMPT environment variables to be configured.
If emoData is not provided, the endpoint will still process the transcript with an empty emotion context.

Build docs developers (and LLMs) love