Rest API Documentation for OpenAI

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

Currently we support Chat and Completion actions on OpenAI via REST API. Additional actions will be supported in the future. For image actions, try our Node NPM or Python PIP modules.

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 openAI (i.e. the prompts) and the response from openAI, 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": "openai",
 "type": "chat",
 "version": "1.0.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
}
}
  • "format" is required and should be set to "openai"
  • "type" can either be "chat" or "completion" 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 openAI request made in millisecond format
  • "response" timestamp when openAI 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": "text-davinci-003",
 "prompt": "say this is a test",
 "max_tokens": 7,
 "temperature": 0
}
}
  • The request object is the complete JSON sent to openAI for a Chat or Completion
  • Include all the same fields sent to openAI

Response parameters (required)

{
"response": {
 "id": "cmpl-abcdef1234",
 "object": "text_completion",
 "created": 1589478378,
 "model": "text-davinci-003",
 "choices": [{
  "text": "\n\nThis is indeed a test",
  "index": 0,
  "logprobs": null,
  "finish_reason": "length"
 }],
 "usage": {
  "prompt_tokens": 5,
  "completion_tokens": 7,
  "total_tokens": 12
 }
  • The response object is the exact JSON data returned from openAI
  • Include all the same fields received fromopenAI

Chat Example

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

{
"reconify": {
 "format": "openai",
 "type": "chat",
 "version": "1.0.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
},
"timestamps": {
 "request": 1689703471457,
 "response": 1689703474393
},
"user": {
 "userId": "ABC123",
 "firstName": "Jane",
 "lastName": "Doe"
},
"request": {
 "model": "gpt-3.5-turbo-0613",
 "messages": [
  { "role" : "system", "content": "You are a stand up comic" },
  { "role" : "user", "content": "Tell a cat joke" }
 ]
},
"response": {
 "id": "chatcmpl-abcdef",
 "object": "chat.completion",
 "created": 1689703472,
 "model": "gpt-3.5-turbo-0613",
 "choices": [{
  "index": 0,
  "message": {
   "role" : "assistant",
   "content" : "Sure, here's a cat joke for you: \n\nWhy don't cats play poker in the wild?\n\nBecause there are too many cheetahs!",
  },
   "finish_reason": "stop"
 }],
 "usage": {
  "prompt_tokens": 21,
  "completion_tokens": 31,
  "total_tokens": 52
  }
 }
}

Completion Example

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

{
"reconify": {
 "format": "openai",
 "type": "completion",
 "version": "1.0.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
},
"timestamps": {
 "request": 1686091778298,
 "response": 1686091844345
},
"user": {
 "userId": "ABC123",
 "firstName": "Jane",
 "lastName": "Doe"
},
"request": {
 "model": "text-davinci-003",
 "prompt": "say this is a test",
 "max_tokens": 7,
 "temperature": 0
},
"response": {
 "id": "cmpl-abcdef1234",
 "object": "text_completion",
 "created": 1589478378,
 "model": "text-davinci-003",
 "choices": [{
  "text": "\n\nThis is indeed a test",
  "index": 0,
  "logprobs": null,
  "finish_reason": "length"
 }],
 "usage": {
  "prompt_tokens": 5,
  "completion_tokens": 7,
  "total_tokens": 12
  }
 }
}