Rest API Documentation for Anthropic

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

Currently we support chat and completions on Anthropic 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 Anthropic (i.e. the prompts) and the response from Anthropic, 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": "anthropic",
 "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 "anthropic"
  • "type" should be "chat" 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 Anthropic request made in millisecond format
  • "response" timestamp when Anthropic 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": "claude-2",
  "max_tokens_to_sample": 300,
  "prompt": "\n\nHuman: Tell me a cat joke\n\nAssistant:"
}
}
  • The request object is the complete JSON sent to Anthropic
  • Include all the same fields sent to Anthropic

Response parameters (required)

{
"response": {
   "completion": "Here's a silly cat joke:\n\nWhy don't cats play poker in the jungle? Too many cheetahs!",
  "stop_reason": "stop_sequence",
  "model": "claude-2.1",
  "stop": "\n\nHuman:",
  "log_id": "1106334994b78ba877c8f4ce0442910640381ae54b819019e134ce717867d339"
 }
 }
  • The response object is the exact JSON data returned from Anthropic
  • Include all the same fields received from Anthropic

Chat Example

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

{
   "reconify": {
       "format": "anthropic",
       "type": "chat",
       "version": "3.0.0",
       "appKey": process.env.RECONIFY_APP_KEY,
       "apiKey": process.env.RECONIFY_API_KEY
   },
   "timestamps": {
       "request": 1709495294482,
       "response": 1709495296398
   },
   "user": {
       "userId": "ABC123",
       "firstName": "Jane",
       "lastNam": "Doe"
   },
   "request": {
       "model": "claude-2.1",
       "max_tokens": 300,
       "messages": [
           {
               "role": "user",
               "content": "Tell me a cat joke"
           }
       ],
       "system": "you are a comic"
   },
    "response": {
       "id": "msg_01P73dhZUgZ51JTkiFMgVopJ",
       "type": "message",
       "role": "assistant",
       "content": [
           {
               "type": "text",
               "text": "Here's a silly cat joke:\n\nWhy don't cats play poker in the jungle? Too many cheetahs!"
           }
       ],
       "model": "claude-2.1",
       "stop_reason": "end_turn",
       "stop_sequence": null,
       "usage": {
           "input_tokens": 18,
           "output_tokens": 29
       }
   }
}

Completions Example

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

{
   "reconify": {
       "format": "anthropic",
       "type": "completion",
       "version": "2.1.0",
       "appKey": process.env.RECONIFY_APP_KEY,
       "apiKey": process.env.RECONIFY_API_KEY
   },
   "timestamps": {
       "request": 1701391185825,
       "response": 1701391187868
   },
   "user": {
       "userId": "ABC123",
       "firstName": "Jane",
       "lastNam": "Doe"
   },
   "request": {
       "model": "claude-2",
       "max_tokens_to_sample": 300,
       "prompt": "\n\nHuman: Tell me a cat joke\n\nAssistant:"
   },
   "response": {
       "completion": " Here's a silly cat joke:\n\nWhy don't cats play poker in the jungle? Too many cheetahs!",
       "stop_reason": "stop_sequence",
       "model": "claude-2.1",
       "stop": "\n\nHuman:",
       "log_id": "1106334994b78ba877c8f4ce0442910640381ae54b819019e134ce717867d339"
   }
}