> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mycura.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Thread Info

> Retrieve information about a conversation thread

## Overview

Retrieves detailed information about a conversation thread, including message count, patient linkage, activity timestamps, and expiration status.

### Authentication

<ParamField header="X-API-Key" type="string" required>
  Your Cura API key
</ParamField>

### Path Parameters

<ParamField path="id" type="string" required>
  The 5-digit thread ID (e.g., `82451`)
</ParamField>

## Request Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.mycura.org/api/cura/threads/82451" \
    -H "X-API-Key: YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios');

  const response = await axios.get(
    'https://api.mycura.org/api/cura/threads/82451',
    {
      headers: {
        'X-API-Key': 'YOUR_API_KEY'
      }
    }
  );

  console.log(response.data.thread);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.mycura.org/api/cura/threads/82451',
      headers={
          'X-API-Key': 'YOUR_API_KEY'
      }
  )

  thread = response.json()['thread']
  print(f"Messages: {thread['messageCount']}")
  print(f"Expires: {thread['expiresAt']}")
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://api.mycura.org/api/cura/threads/82451');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'X-API-Key: YOUR_API_KEY'
  ]);

  $response = curl_exec($ch);
  $data = json_decode($response, true);
  $thread = $data['thread'];

  echo "Thread ID: " . $thread['threadId'] . "\n";
  echo "Messages: " . $thread['messageCount'] . "\n";
  ?>
  ```
</CodeGroup>

## Response

<ResponseField name="success" type="boolean">
  Whether the request was successful
</ResponseField>

<ResponseField name="thread" type="object">
  Thread information object

  <Expandable title="Thread Properties">
    <ResponseField name="threadId" type="string">
      The 5-digit thread identifier
    </ResponseField>

    <ResponseField name="patientId" type="string | null">
      UUID of linked patient (null if not linked)
    </ResponseField>

    <ResponseField name="messageCount" type="integer">
      Total number of messages in the thread (user + assistant)
    </ResponseField>

    <ResponseField name="lastActivity" type="string (ISO 8601)">
      Timestamp of the last message sent to this thread
    </ResponseField>

    <ResponseField name="createdAt" type="string (ISO 8601)">
      Timestamp when the thread was created
    </ResponseField>

    <ResponseField name="expiresAt" type="string (ISO 8601)">
      Timestamp when the thread will auto-delete (30 minutes from last activity)
    </ResponseField>
  </Expandable>
</ResponseField>

### Success Response (200)

```json theme={null}
{
  "success": true,
  "thread": {
    "threadId": "82451",
    "patientId": "28dffdd1-c18b-46e4-88f7-9b2f073c70dc",
    "messageCount": 12,
    "lastActivity": "2025-10-22T18:15:30.123Z",
    "createdAt": "2025-10-22T18:05:00.000Z",
    "expiresAt": "2025-10-22T18:45:30.123Z"
  }
}
```

## Error Responses

<ResponseExample>
  ```json 404 Not Found theme={null}
  {
    "error": "Thread not found or expired"
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": "Unauthorized - Invalid API key"
  }
  ```

  ```json 500 Internal Server Error theme={null}
  {
    "error": "Failed to retrieve thread"
  }
  ```
</ResponseExample>

## Use Cases

<CardGroup cols={2}>
  <Card title="Check if Thread is Active" icon="pulse">
    Verify a thread exists before sending messages
  </Card>

  <Card title="Monitor Expiration" icon="hourglass">
    Check when the thread will expire to warn users
  </Card>

  <Card title="Track Conversation Length" icon="chart-line">
    See how many messages have been exchanged
  </Card>

  <Card title="Verify Patient Linkage" icon="link">
    Confirm which patient (if any) the thread is linked to
  </Card>
</CardGroup>

## Example: Check Expiration

```javascript theme={null}
async function isThreadExpired(threadId) {
  try {
    const response = await axios.get(
      `https://api.mycura.org/api/cura/threads/${threadId}`,
      {
        headers: { 'X-API-Key': 'YOUR_API_KEY' }
      }
    );
    
    const expiresAt = new Date(response.data.thread.expiresAt);
    const now = new Date();
    
    if (expiresAt < now) {
      return true; // Expired
    }
    
    const minutesLeft = Math.floor((expiresAt - now) / 1000 / 60);
    console.log(`Thread expires in ${minutesLeft} minutes`);
    return false;
    
  } catch (error) {
    if (error.response?.status === 404) {
      return true; // Thread not found = expired/deleted
    }
    throw error;
  }
}
```

## Example: Display Thread Stats

```javascript theme={null}
async function displayThreadStats(threadId) {
  const response = await axios.get(
    `https://api.mycura.org/api/cura/threads/${threadId}`,
    {
      headers: { 'X-API-Key': 'YOUR_API_KEY' }
    }
  );
  
  const { thread } = response.data;
  
  console.log(`
    Thread Information
    ==================
    ID: ${thread.threadId}
    Patient Linked: ${thread.patientId ? 'Yes' : 'No'}
    Total Messages: ${thread.messageCount}
    Age: ${getTimeSince(thread.createdAt)}
    Last Active: ${getTimeSince(thread.lastActivity)}
    Expires In: ${getTimeUntil(thread.expiresAt)}
  `);
}

function getTimeSince(timestamp) {
  const minutes = Math.floor((Date.now() - new Date(timestamp)) / 1000 / 60);
  return `${minutes} minutes ago`;
}

function getTimeUntil(timestamp) {
  const minutes = Math.floor((new Date(timestamp) - Date.now()) / 1000 / 60);
  return `${minutes} minutes`;
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Check expiration before long operations">
    Before starting a multi-message flow, verify the thread is still active:

    ```javascript theme={null}
    async function sendMultipleMessages(threadId, messages) {
      // Check thread status first
      const threadInfo = await getThreadInfo(threadId);
      if (!threadInfo) {
        throw new Error('Thread expired - please create a new one');
      }
      
      // Proceed with messages
      for (const msg of messages) {
        await chat({ threadId, message: msg });
      }
    }
    ```
  </Accordion>

  <Accordion title="Display expiration warnings to users">
    Show users when their thread is about to expire:

    ```javascript theme={null}
    function showExpirationWarning(expiresAt) {
      const minutesLeft = Math.floor(
        (new Date(expiresAt) - Date.now()) / 1000 / 60
      );
      
      if (minutesLeft < 5) {
        alert(`Your conversation will expire in ${minutesLeft} minutes!`);
      }
    }
    ```
  </Accordion>

  <Accordion title="Use for analytics and monitoring">
    Track thread usage patterns:

    ```javascript theme={null}
    async function logThreadMetrics(threadId) {
      const { thread } = await getThreadInfo(threadId);
      
      await analytics.track('thread_activity', {
        threadId: thread.threadId,
        messageCount: thread.messageCount,
        duration: new Date(thread.lastActivity) - new Date(thread.createdAt),
        hasPatient: !!thread.patientId
      });
    }
    ```
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={3}>
  <Card title="Create Thread" icon="plus" href="/api-reference/endpoint/create-thread">
    Start a new conversation
  </Card>

  <Card title="Chat" icon="message" href="/api-reference/endpoint/chat">
    Send messages to the thread
  </Card>

  <Card title="Delete Thread" icon="trash" href="/api-reference/endpoint/delete-thread">
    Manually end the conversation
  </Card>
</CardGroup>

## Next Steps

<Card title="Learn About Conversation Threads" icon="book" href="/conversation-threads">
  Comprehensive guide to thread features and best practices
</Card>
