GET
/
v4
/
threads
/
{thread_id}
/
messages
import SGPClient from 'sgp';

const client = new SGPClient({
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

async function main() {
  const chatThreadHistory = await client.chatThreads.messages.retrieve('thread_id');

  console.log(chatThreadHistory.application_spec_id);
}

main();
{
  "thread": {
    "id": "<string>",
    "title": "<string>",
    "application_variant_id": "<string>",
    "thread_metadata": {},
    "account_id": "<string>",
    "created_by_user_id": "<string>",
    "created_at": "2023-11-07T05:31:56Z",
    "archived_at": "2023-11-07T05:31:56Z",
    "updated_at": "2023-11-07T05:31:56Z"
  },
  "messages": [
    {
      "entry": {
        "id": "<string>",
        "input": {},
        "output": {},
        "aggregated": true,
        "application_spec_id": "<string>",
        "application_variant_id": "<string>",
        "start_timestamp": "2023-11-07T05:31:56Z",
        "duration_ms": 123,
        "operation_status": "SUCCESS",
        "operation_metadata": {},
        "chat_thread_id": "<string>",
        "interaction_source": "EXTERNAL_AI",
        "created_at": "2023-11-07T05:31:56Z"
      },
      "spans": [
        {
          "id": "<string>",
          "application_interaction_id": "<string>",
          "node_id": "<string>",
          "operation_type": "TEXT_INPUT",
          "operation_status": "SUCCESS",
          "operation_input": {},
          "operation_output": {},
          "operation_expected": {},
          "operation_metadata": {},
          "start_timestamp": "2023-11-07T05:31:56Z",
          "duration_ms": 123
        }
      ],
      "feedback": {
        "id": "<string>",
        "chat_thread_id": "<string>",
        "application_interaction_id": "<string>",
        "sentiment": "positive",
        "description": "<string>",
        "created_at": "2023-11-07T05:31:56Z"
      }
    }
  ],
  "application_spec_id": "<string>"
}

Authorizations

x-api-key
string
header
required

Headers

x-selected-account-id
string | null

Path Parameters

thread_id
string
required

Query Parameters

fetch_by_account
boolean | null
default:
false

Fetch the thread by account instead of user

fetch_spans
boolean | null
default:
false

Fetch spans for each message

Response

200
application/json
Successful Response
thread
object
required
messages
object[]
required
application_spec_id
string
required

The ID of the application spec that the thread belongs to.