Rest API Documentation for Cohere

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

Currently we support chat and generate completions on Cohere via REST API.

If you are integrating with Amazon Bedrock, refer to the Bedrock Rest documentation.

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 Cohere (i.e. the prompts) and the response from Cohere, 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": "cohere",
 "type": "chat",
 "version": "2.1.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
}
}
  • "format" is required and should be set to "cohere"
  • "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 Cohere request made in millisecond format
  • "response" timestamp when Cohere 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": {
  "model": "command",
  "message": "Tell me one good cat joke"
}
}
  • The request object is the complete JSON sent to Cohere
  • Include all the same fields sent to Cohere

Response parameters (required)

{
   "response": {
       "response_id": "d479aeb3-a87d-41ef-b13f-7a712094106e",
       "text": "Why did the cat cross the road?\nTo get to the meow-niverse!\n\nPurr-fect joke, hahaha? \n\nWould you like to hear another one? \n\nIf you're feeling adventurous, you could even tell me a joke about cats!",
       "generationId": "6e0f59a0-4469-412e-9279-d552f2b51db4",
       "token_count": {
           "prompt_tokens": 68,
           "response_tokens": 59,
           "total_tokens": 127,
           "billed_tokens": 116
       },
       "meta": {
           "api_version": {
               "version": "1"
           },
           "billed_units": {
               "input_tokens": 57,
               "output_tokens": 59
           }
       }
   }
}
  • The response object is the exact JSON data returned from Cohere
  • Include all the same fields received from Cohere

Chat Example

Below is an example JSON to post to the endpoint for a chat completion.

{
   "reconify": {
       "format": "cohere",
       "type": "chat",
       "version": "2.1.0",
       "appKey": process.env.RECONIFY_APP_KEY,
       "apiKey": process.env.RECONIFY_API_KEY
   },
   "timestamps": {
       "request": 1701460517528,
       "response": 1701460522216
   },
   "user": {
       "userId": "ABC123",
       "firstName": "Jane",
       "lastNam": "Doe"
   },
   "request": {
       "model": "command",
       "message": "Tell me one good cat joke"
   },
   "response": {
       "response_id": "d479aeb3-a87d-41ef-b13f-7a712094106e",
       "text": "Why did the cat cross the road?\nTo get to the meow-niverse!\n\nPurr-fect joke, hahaha? \n\nWould you like to hear another one? \n\nIf you're feeling adventurous, you could even tell me a joke about cats!",
       "generationId": "6e0f59a0-4469-412e-9279-d552f2b51db4",
       "token_count": {
           "prompt_tokens": 68,
           "response_tokens": 59,
           "total_tokens": 127,
           "billed_tokens": 116
       },
       "meta": {
           "api_version": {
               "version": "1"
           },
           "billed_units": {
               "input_tokens": 57,
               "output_tokens": 59
           }
       }
   }
}

Generate Example

Below is an example JSON to post to the endpoint for a generate completion.

{
   "reconify": {
       "format": "cohere",
       "type": "generate",
       "version": "2.1.0",
       "appKey": process.env.RECONIFY_APP_KEY,
       "apiKey": process.env.RECONIFY_API_KEY
   },
   "timestamps": {
       "request": 1701460517528,
       "response": 1701460522216
   },
   "user": {
       "userId": "ABC123",
       "firstName": "Jane",
       "lastNam": "Doe"
   },
   "request": {
       "model": "command",
       "message": "write a cat haiku",
       "max_tokens": 300
   },
   "response": {
       "id": "7d05abf3-688a-47d5-8d8e-18ef34ec6178",
       "generations": [
           {
               "id": "7c3206e5-d412-4df3-8ad3-f2335a5d4f53",
               "text": " Independent feline,\nQuietly plotting solitude,\nSpring rain gleams in her eyes. \n\nWould you like me to write another cat haiku? ",
               "finish_reason": "COMPLETE"
           }
       ],
       "prompt": "write a cat haiku",
       "meta": {
           "apiVersion": {
               "version": "1"
           },
           "billed_units": {
               "input_tokens": 5,
               "output_tokens": 33
           }
       }
   }
}