Rest API Documentation for Google Gemini

Below is the documentation for integrating Reconify with Google Gemini via REST API.

Currently we support Generate with text and Chat interactions on Gemini via REST API. For Generate with text and images, please use the Node NPM module.

Get started - Create an account

The first step is to create an account at app.reconify.com.

Generate API and APP Keys

In the Reconify console, add an Application to your account. This will generate both an API_KEY and an APP_KEY which will be used in the code below to send data to Reconify.

Rest API Integration

Below are instructions on integrating with the REST API.

At a high level, you will send a copy of the JSON input into Gemini and the response from Gemini, along with your Reconify API and APP keys. There are additional optional parameters for tracking users and sessions.

Endpoint

Sign up for an account to get the endpoint url.

JSON Payload structure

{
"reconify": {},
"timestamps": {},
"session": "",
"sessionTimeOut": null,
"user": {},
"request": {},
"response": {}
}

Reconify parameters (required)

{
"reconify": {
 "format": "gemini",
 "type": "generate",
 "version": "2.2.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
}
}
  • "format" is required and should be set to "gemini"
  • "type" can either be "chat" or "generate" for the type of interaction
  • "version" is the version of the Reconify REST API
  • "appKey" and "apiKey" are the Reconify values generated when creating the app

Timestamp parameters (optional)

{
"timestamps": {
 "request": 1686091778298,
 "response": 1686091844345
}
}
  • Timestamps are optional, if not passed in, the time the API receives the payload will be used.
  • "request" timestamp when Gemini request made in millisecond format
  • "response" timestamp when Gemini response received in millisecond format. If not present, request will be used for both

Session parameters (optional)

{
"session": "ABCDEF123456",
"sessionTimeout": 10
}
  • Both session parameters are optional
  • "session" an alphanumeric string to indicate the session for grouping interactions
  • "sessionTimeout" is the length of time in minutes to wait for an interaction before ending the current session. The default is 10.

User parameters (optional)

{
"user: {
 "userId": "ABC123",
 "isAuthenticated": 1,
 "firstName": "Jane",
 "lastName": "Doe",
 "email": "some_email",
 "phone": "555-555-5555",
 "gender": "female"
}
}
  • The user object is optional
  • Either "userId" or "email" is required if a user object is sent to track unique users, otherwise users will all be new
  • "userId" is an alphanumeric string unique for the user
  • "isAuthenticated" is optional and can be 1 or 0 to track logged in users
  • "firstName" and "lastName" are optional alphanumeric strings
  • "email" is an optional alphanumeric string, it is used to identify a user if a userId is not present
  • "phone" is optional
  • "gender" is optional

Request parameters (required)

{
"request": {
  "contents": [
    {
      "parts": [
        {
          "text": "Tell a cat joke"
        }
       ]
    }
  ],
  "model": "gemini-pro",
  "generationConfig": {
     "maxOutputTokens": 350
  },
  "safetySettings": []
}
}
  • The request object is the complete JSON sent to Gemini
  • Include all the same fields sent to Gemini
  • Add an additional "model" field to specify which model was used
  • The contents array is required
  • The generationConfig and safetySettings are optional

Response parameters (required)

{
"response": {
       "candidates": [
           {
               "content": {
                   "parts": [
                       {
                           "text": "Why did the cat join the Red Cross?\nBecause he wanted to be a first-aid kitty!"
                       }
                   ],
                   "role": "model"
               },
               "finishReason": "STOP",
               "index": 0,
               "safetyRatings": [
                   {
                       "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                       "probability": "NEGLIGIBLE"
                   },
                   {
                       "category": "HARM_CATEGORY_HATE_SPEECH",
                       "probability": "NEGLIGIBLE"
                   },
                   {
                       "category": "HARM_CATEGORY_HARASSMENT",
                       "probability": "NEGLIGIBLE"
                   },
                   {
                       "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                       "probability": "NEGLIGIBLE"
                   }
               ]
           }
       ],
       "promptFeedback": {
           "safetyRatings": [
               {
                   "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                   "probability": "NEGLIGIBLE"
               },
               {
                   "category": "HARM_CATEGORY_HATE_SPEECH",
                   "probability": "NEGLIGIBLE"
               },
               {
                   "category": "HARM_CATEGORY_HARASSMENT",
                   "probability": "NEGLIGIBLE"
               },
               {
                   "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                   "probability": "NEGLIGIBLE"
               }
           ]
       }
}
  • The response object is the exact JSON data returned from Gemini
  • Include all the same fields received from Gemini

Example: Generate with Text

Below is an example JSON to post to the endpoint for a Generate action.

{
   "reconify": {
       "format": "gemini",
       "type": "generate",
       "version": "2.3.0",
       "appKey": process.env.RECONIFY_APP_KEY,
       "apiKey": process.env.RECONIFY_API_KEY
   },
   "timestamps": {
       "request": 1703135407816,
       "response": 1703135409193
   },
   "user": {
       "userId": "ABC123",
       "firstName": "Jane",
       "lastName": "Doe"
   },
   "request": {
       "contents": [
          {
             "parts": [
                {
                   "text": "Tell a cat joke"
                   }
             ]
          }
       ],
       "model": "gemini-pro",
       "generationConfig": {
          "maxOutputTokens": 350
       },
       "safetySettings": []
   },
    "candidates": [
      {
         "content": {
            "parts": [
               {
                  "text": "Why did the cat join the Red Cross?\nBecause he wanted to be a first-aid kitty!"
               }
             ],
            "role": "model"
          },
          "finishReason": "STOP",
          "index": 0,
          "safetyRatings": [
             {
                "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                "probability": "NEGLIGIBLE"
             },
             {
                "category": "HARM_CATEGORY_HATE_SPEECH",
                "probability": "NEGLIGIBLE"
             },
             {
                "category": "HARM_CATEGORY_HARASSMENT",
                "probability": "NEGLIGIBLE"
             },
             {
                "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                "probability": "NEGLIGIBLE"
             }
           ]
      }
    ],
    "promptFeedback": {
       "safetyRatings": [
             {
                 "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                 "probability": "NEGLIGIBLE"
             },
             {
                 "category": "HARM_CATEGORY_HATE_SPEECH",
                 "probability": "NEGLIGIBLE"
             },
             {
                 "category": "HARM_CATEGORY_HARASSMENT",
                 "probability": "NEGLIGIBLE"
             },
             {
                 "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                 "probability": "NEGLIGIBLE"
             }
       ]
    }
}

Example: Chat

Below is an example JSON to post to the endpoint for a Chat action.

{
   "reconify": {
       "format": "gemini",
       "type": "chat",
       "version": "2.3.0",
       "appKey": process.env.RECONIFY_APP_KEY,
       "apiKey": process.env.RECONIFY_API_KEY
   },
   "timestamps": {
       "request": 1703135407816,        
        "response": 1703135409193
   },
   "user": {
       "userId": "ABC123",
       "firstName": "Jane",
       "lastName": "Doe"
   },
   "request": {
       "contents": [
          {
             "role" : "user",
             "parts": [
                {
                   "text": "I have a tuxedo cat and a calico cat"
                }
             ]
          },
          {
             "role" : "model",
             "parts": [
                {
                   "text": "How can I help?"
                }
             ]
          },
          {
             "role" : "user",
             "parts": [
                {
                   "text": "How many colors are my cats?"
                }
             ]
          }
       ],
       "model": "gemini-pro",
       "generationConfig": {
          "maxOutputTokens": 200
       },
   },
    "candidates": [
      {
         "content": {
            "parts": [
               {
                  "text": "Tuxedo cats typically have two colors: black and white. However, some tuxedo cats may also have a small amount of orange or tabby markings. Calico cats typically have three colors: black, orange, and white. However, the exact colors and patterns of a calico cat can vary widely.\n\nTuxedo Cat Colors:\n\n* Black and white\n* Black, white, and orange\n* Black, white, and tabby\n\nCalico Cat Colors:\n\n* Black, orange, and white\n* Blue, cream, and white\n* Red, cream, and white\n* Chocolate, orange, and white\n* Lilac, cream, and white\n* Cinnamon, orange, and white\n* Fawn, cream, and white\n\nIt is important to note that these are just the most common colors and patterns for tuxedo and calico cats. There is a wide variety of coat colors and patterns that can occur in both breeds."
               }
             ],
            "role": "model"
          },
          "finishReason": "STOP",
          "index": 0,
          "safetyRatings": [
             {
                "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                "probability": "NEGLIGIBLE"
             },
             {
                "category": "HARM_CATEGORY_HATE_SPEECH",
                "probability": "NEGLIGIBLE"
             },
             {
                "category": "HARM_CATEGORY_HARASSMENT",
                "probability": "NEGLIGIBLE"
             },
             {
                "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                "probability": "NEGLIGIBLE"
             }
           ]
      }
    ],
    "promptFeedback": {
       "safetyRatings": [
             {
                 "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                 "probability": "NEGLIGIBLE"
             },
             {
                 "category": "HARM_CATEGORY_HATE_SPEECH",
                 "probability": "NEGLIGIBLE"
             },
             {
                 "category": "HARM_CATEGORY_HARASSMENT",
                 "probability": "NEGLIGIBLE"
             },
             {
                 "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                 "probability": "NEGLIGIBLE"
             }
       ]
    }
}