Skip to content

Conversation API

The Conversations API allows you to create and manage conversations with Cognipeer AI assistants (peers). Each conversation represents a session between a user and a peer.

Create Conversation

Creates a new conversation with a specific peer.

Request

POST /v1/client/conversation

Request Body

json
{
  "peerId": "90aa68af-d5c4-4b60-b63e-b732db08bb46"
}

Body Parameters

ParameterTypeRequiredDescription
peerIdstringYesID of the peer to create a conversation with

Response

json
{
  "status": "success",
  "data": {
    "_id": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
    "peerId": "90aa68af-d5c4-4b60-b63e-b732db08bb46",
    "userId": "usr_12345",
    "createdAt": "2025-04-14T15:30:45.000Z",
    "updatedAt": "2025-04-14T15:30:45.000Z"
  }
}

List Conversations

Retrieves a list of conversations for the authenticated user.

Request

GET /v1/client/conversation

Query Parameters

ParameterTypeRequiredDescription
peerIdstringNoFilter conversations by peer ID
limitintegerNoMaximum number of conversations to return. Default: 10, Max: 100
skipintegerNoNumber of conversations to skip. Default: 0

Response

json
{
  "status": "success",
  "data": [
    {
      "_id": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
      "peerId": "90aa68af-d5c4-4b60-b63e-b732db08bb46",
      "userId": "usr_12345",
      "lastMessage": {
        "content": "How can I help you today?",
        "role": "ai",
        "createdAt": "2025-04-14T15:30:45.000Z"
      },
      "createdAt": "2025-04-14T15:30:45.000Z",
      "updatedAt": "2025-04-14T15:35:12.000Z"
    },
    {
      "_id": "2a3b4c5d-6e7f-8g9h-0i1j-2k3l4m5n6o7p",
      "peerId": "7b45cd12-a987-4321-b555-e789f0123456",
      "userId": "usr_12345",
      "lastMessage": {
        "content": "What products are available?",
        "role": "user",
        "createdAt": "2025-04-12T10:22:33.000Z"
      },
      "createdAt": "2025-04-12T10:20:18.000Z",
      "updatedAt": "2025-04-12T10:22:33.000Z"
    }
  ]
}

Get Conversation

Retrieves details about a specific conversation.

Request

GET /v1/client/conversation/{conversationId}

Path Parameters

ParameterTypeRequiredDescription
conversationIdstringYesID of the conversation to retrieve

Response

json
{
  "status": "success",
  "data": {
    "_id": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
    "peerId": "90aa68af-d5c4-4b60-b63e-b732db08bb46",
    "userId": "usr_12345",
    "createdAt": "2025-04-14T15:30:45.000Z",
    "updatedAt": "2025-04-14T15:35:12.000Z"
  }
}

Get Conversation Messages

Retrieves messages from a specific conversation.

Request

GET /v1/client/conversation/{conversationId}/message

Path Parameters

ParameterTypeRequiredDescription
conversationIdstringYesID of the conversation to retrieve messages from

Query Parameters

ParameterTypeRequiredDescription
limitintegerNoMaximum number of messages to return. Default: 10, Max: 100
skipstringNoNumber of messages to skip. Default: 0

Response

json
{
  "status": "success",
  "data": [
    {
      "_id": "msg_12345",
      "conversationId": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
      "content": "Hello, how can I help you today?",
      "role": "ai",
      "createdAt": "2025-04-14T15:30:45.000Z"
    },
    {
      "_id": "msg_12346",
      "conversationId": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
      "content": "I'm looking for information about your premium plan.",
      "role": "user",
      "createdAt": "2025-04-14T15:31:22.000Z"
    },
    {
      "_id": "msg_12347",
      "conversationId": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
      "content": "Our premium plan offers several benefits...",
      "role": "ai",
      "createdAt": "2025-04-14T15:31:45.000Z"
    }
  ]
}

Send Message

Sends a message to an existing conversation.

Request

POST /v1/client/conversation/{conversationId}/message

Path Parameters

ParameterTypeRequiredDescription
conversationIdstringYesID of the conversation to send a message to

Request Body

json
{
  "content": "What features are included in the premium plan?",
  "responseFormat": "text"
}

Body Parameters

ParameterTypeRequiredDescription
contentstringYesThe message content
responseFormatstringNoFormat of the response. Can be 'text' (default) or 'json'
responseSchemaobjectNoJSON schema for structured responses (when responseFormat is 'json')

Response (Text Format)

json
{
  "status": "success",
  "data": {
    "_id": "msg_12348",
    "conversationId": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
    "content": "The premium plan includes the following features: 1. Advanced analytics...",
    "role": "ai",
    "createdAt": "2025-04-14T15:32:15.000Z"
  }
}

Response (JSON Format)

json
{
  "status": "success",
  "data": {
    "_id": "msg_12348",
    "conversationId": "7c8d9e0f-1a2b-3c4d-5e6f-7g8h9i0j1k2l",
    "content": "Response in JSON format",
    "role": "ai",
    "output": {
      "features": [
        {
          "name": "Advanced Analytics",
          "description": "Detailed insights into user interactions and AI performance"
        },
        {
          "name": "Custom Branding",
          "description": "Ability to fully customize the appearance of your AI assistants"
        },
        {
          "name": "Priority Support",
          "description": "24/7 dedicated technical support"
        }
      ],
      "pricing": {
        "monthly": 199.99,
        "annual": 1999.99
      }
    },
    "createdAt": "2025-04-14T15:32:15.000Z"
  }
}

Error Responses

Status CodeError CodeDescription
400invalid_requestThe request was malformed or missing required parameters
401unauthorizedThe API key is invalid or missing
403forbiddenThe API key does not have permission to perform this action
404conversation_not_foundThe specified conversation does not exist
429rate_limit_exceededToo many requests in a given amount of time
500server_errorAn unexpected error occurred on the server

Built with VitePress