Rest API Documentation for Bedrock

Below is the documentation for integration Reconify with Amazon Bedrock Runtime via REST API.

Currently the REST API for Bedrock ony supports Chat actions with the following foundational models: Amazon Titan, AI21 Jurassic, Anthropic Claude, Cohere Command, Meta Llama 2, and Mistral. For image support with Stable Diffusion or Amazon Titan, try the 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 JSON copy of the same input into the Bedrock Runtime invoke_model() method, and a copy of the response body, 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": "bedrock",
 "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 "bedrock"
  • "type" is "chat" (for images, use the PIP model; in the future the REST API will support more types)
  • "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, however, if not passed in, the time the API receives the payload will be used.
  • "request" timestamp is when the request was made via invoke_model() in millisecond format
  • "response" timestamp is when the response was 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": {
 "modelId": "anthropic.claude-instant-v1",
 "contentType": "application/json",
  "accept": "application/json",
  "body": "{\"prompt\":\"\\n\\nHuman: Tell a cat joke.\\n\\nAssistant:\", \"max_tokens_to_sample\":300, \"temperature\":1, \"top_k\":250, \"top_p\":0.999, \"stop_sequences\":[\"\\n\\nHuman:\"], \"anthropic_version\":\"bedrock-2023-05-31\"}"
}
}
  • The request object is a JSON copy of the same inputs to the Bedrock Runtime invoke_model() method.
  • Include all the same fields sent to Bedrock

Response parameters (required)

{
"response": {
  "requestId": "54425f31-4c82-426e-a69c-efe05c886cd0",
 "body": {
   "completion": " Here is a cat joke in the voice of Jerry Seinfeld:\n\nWhat's the deal with cats, huh? They sleep all day and then right when you're trying to relax after a long day, that's when they want to play. It's like 'Hey buddy, I just got home. Think I could have a little me time here? But no, the minute I sit down you bring me your favorite mouse toy. What's up with that?' \n\nAnd don't even get me started on the litter box thing. So they use a box filled with sand to do their business, but everything else in the house is fair game? I find litter all over. It's under the couch, behind the TV, in my sneakers. Like they're leaving me a trail of clues for some scavenger hunt. And it's not just a few pieces, it's clumps! Clumps of litter everywhere! \n\nYou know, cats are funny creatures. They wake you up at 4am just to be fed, but then during the day it's like 'Hey, buddy, what's your problem? Tryna take a nap here.' Am I right? The whole cat thing, it's just one big puzzle. What's the deal?",
   "stop_reason": "stop_sequence"
 }
 }
  • The requestId is optional. It is the ID found in the meta data of the response from invoke_model(): ResponseMetadata.RequestId
  • The body is required and is the JSON of the "body" field in the response from invoke_module(). Remember to convert the "body" from botocore.response.StreamingBody to JSON. For example: json.loads(response["body"].read().decode('utf-8'))

Example with Anthropic Claude

Below is an example JSON to post to the endpoint.

{
"reconify": {
 "format": "bedrock",
 "type": "chat",
 "version": "1.0.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
},
"timestamps": {
 "request": 1696450259007,
 "response": 1696450283264
},
"user": {
 "userId": "ABC123",
 "firstName": "Jane",
 "lastName": "Doe"
},
"request": {
 "modelId": "anthropic.claude-instant-v1",
  "contentType": "application/json",
  "accept": "application/json",
  "body": "{\"prompt\":\"\n\nHuman: Create a cat joke in the voice of Jerry Seinfeld.\n\nAssistant:\", \"max_tokens_to_sample\":300, \"temperature\":1, \"top_k\":250, \"top_p\":0.999, \"stop_sequences\":[\"\n\nHuman:\"], \"anthropic_version\":\"bedrock-2023-05-31\"}"
},
"response": {
 "requestId": "54425f31-4c82-426e-a69c-efe05c886cd0",
  "body": {
    "completion": " Here is a cat joke in the voice of Jerry Seinfeld:\n\nWhat's the deal with cats, huh? They sleep all day and then right when you're trying to relax after a long day, that's when they want to play. It's like 'Hey buddy, I just got home. Think I could have a little me time here? But no, the minute I sit down you bring me your favorite mouse toy. What's up with that?' \n\nAnd don't even get me started on the litter box thing. So they use a box filled with sand to do their business, but everything else in the house is fair game? I find litter all over. It's under the couch, behind the TV, in my sneakers. Like they're leaving me a trail of clues for some scavenger hunt. And it's not just a few pieces, it's clumps! Clumps of litter everywhere! \n\nYou know, cats are funny creatures. They wake you up at 4am just to be fed, but then during the day it's like 'Hey, buddy, what's your problem? Tryna take a nap here.' Am I right? The whole cat thing, it's just one big puzzle. What's the deal?",
    "stop_reason": "stop_sequence"
 }
 }
}

Example with Cohere Command

Below is an example JSON to post to the endpoint.

{
"reconify": {
 "format": "bedrock",
 "type": "chat",
 "version": "1.0.0",
 "appKey": process.env.RECONIFY_APP_KEY,
 "apiKey": process.env.RECONIFY_API_KEY
},
"timestamps": {
 "request": 1696456064984,
 "response": 1696456077201
},
"user": {
 "userId": "ABC123",
 "firstName": "Jane",
 "lastName": "Doe"
},
"request": {
 "modelId": "cohere.command-text-v14",
  "contentType": "application/json",
  "accept": "application/json",
  "body": "{\"prompt\":\"Create a cat joke in the voice of Jerry Seinfeld.\", \"max_tokens\":400, \"temperature\":0.75, \"p\":0.01, \"k\":0, \"stop_sequences\":[], \"return_likelihoods\":\"NONE\"}"
},
"response": {
 "requestId": "72aa53af-21ef-4b6e-8e1d-4bb23e85a0d2",
  "body": {
   "generations": [
     {
       "id": "08dbd029-273e-4674-bbe0-5e0687e78079",
       "text": " Why did the cat go to the chiropractor?\nTo get its spine aligned."
     }
   ],
   "id": "72aa53af-21ef-4b6e-8e1d-4bb23e85a0d2",
   "prompt": "Create a cat joke in the voice of Jerry Seinfeld."
 }
 }
}