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

# Transcripts

> REST endpoints for retrieving transcription history

## Get Transcript History

Retrieve transcription history for an app session.

### Endpoint

<CodeGroup>
  ```bash Production theme={null}
  GET https://api.mentra.glass/api/transcripts/:appSessionId
  ```

  ```bash Development theme={null}
  GET https://devapi.mentra.glass/api/transcripts/:appSessionId
  ```

  ```bash Local theme={null}
  GET http://localhost:8002/api/transcripts/:appSessionId
  ```
</CodeGroup>

### Headers

```
X-API-Key: <appApiKey>
X-Package-Name: <packageName>
```

<Warning>
  The code shows this endpoint is incorrectly defined as `/api/transcripts/:appSessionId` at line 18, but it should be just `/transcripts/:appSessionId` since the router is mounted at `/api`.
</Warning>

### Parameters

| Parameter      | Type   | Description                         |
| -------------- | ------ | ----------------------------------- |
| `appSessionId` | string | The app session identifier (in URL) |

### Query Parameters

| Parameter   | Type   | Description                                                 |
| ----------- | ------ | ----------------------------------------------------------- |
| `duration`  | number | Seconds to look back from now                               |
| `startTime` | string | Start time for transcript range (ISO format)                |
| `endTime`   | string | End time for transcript range (ISO format)                  |
| `language`  | string | Language code (e.g., 'en-US', 'fr-FR'), defaults to 'en-US' |

<Note>
  You must provide either `duration` OR `startTime`/`endTime` parameters.
</Note>

### Response

Success (200):

```json theme={null}
{
  "language": "en-US",
  "segments": [
    {
      "speakerId": "speaker-1",
      "resultId": "1705748400000-abc123",
      "text": "Hello, how are you today?",
      "timestamp": "2024-01-20T10:00:00.000Z",
      "isFinal": true
    },
    {
      "speakerId": "speaker-1",
      "resultId": "1705748403000-def456",
      "text": "I'm doing great, thanks!",
      "timestamp": "2024-01-20T10:00:03.000Z",
      "isFinal": true
    }
  ]
}
```

Error (400):

```json theme={null}
{
  "error": "duration, startTime, or endTime is required"
}
```

Error (404):

```json theme={null}
{
  "error": "Session not found"
}
```

Error (500):

```json theme={null}
{
  "error": "Error fetching transcripts"
}
```

### Implementation

* **File**: `packages/cloud/src/routes/transcripts.routes.ts:18-70`
* **Service**: Uses `TranscriptionManager.getTranscriptHistory()`
* **Session**: Extracts user session ID from app session ID by splitting on '-'

### Time Range Options

1. **Duration-based** (most common):
   ```
   GET /api/transcripts/session-123?duration=300&language=en-US
   ```
   Returns last 5 minutes (300 seconds) of transcripts

2. **Time range**:
   ```
   GET /api/transcripts/session-123?startTime=2024-01-20T10:00:00Z&endTime=2024-01-20T10:30:00Z
   ```
   Returns transcripts within specific time range

### Transcript Segment Structure

Each segment is a `TranscriptSegment` object containing:

* `speakerId`: Optional speaker identifier
* `resultId`: Unique identifier for this transcript segment
* `text`: The transcribed text
* `timestamp`: ISO timestamp when the segment was created
* `isFinal`: Whether this is a final or interim result

## Language Support

The system supports multiple languages for transcription. Common language codes include:

* `en-US` - English (US) - default
* `es-ES` - Spanish (Spain)
* `fr-FR` - French (France)
* `de-DE` - German (Germany)
* `it-IT` - Italian (Italy)
* `pt-BR` - Portuguese (Brazil)
* `ja-JP` - Japanese (Japan)
* `ko-KR` - Korean (Korea)
* `zh-CN` - Chinese (Simplified)

## Session ID Format

The `appSessionId` parameter follows the format: `{userSessionId}-{appIdentifier}`

For example: `session123-com.example.app`

The endpoint extracts the user session ID by splitting on the first hyphen.

## Error Codes

| Code | Description                                                   |
| ---- | ------------------------------------------------------------- |
| 400  | Missing required parameters (duration, startTime, or endTime) |
| 404  | Session not found                                             |
| 500  | Internal server error                                         |

## Notes

* Transcripts are stored in memory per user session
* Historical data availability depends on session duration
* Language filtering returns only transcripts in the specified language
* Apps should authenticate using API key headers (though validation is not shown in the current implementation)
* Console logs are present for debugging (lines 26, 59)
