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

# Get Context

> Retrieve AI context including relevant memories and recent conversations.

Generate context for LLM prompts by retrieving the most relevant memories and recent messages
for a user. Use this to manually inject memory context into your AI applications.

**Path Parameters:**
- `custom_user_id` (str): Unique identifier for the user
- `session_id` (UUID): Session UUID to get context from

**Query Parameters:**
- `recall_strategy` (RecallStrategy): Memory retrieval strategy. Options: low_latency, balanced, agentic and auto. Default: balanced
- `min_top_k` (int): Minimum number of memories to return. Range: 5-50. Default: 15
- `max_top_k` (int): Maximum number of memories to return. Range: 10-100. Default: 50
- `memories_threshold` (float): Similarity threshold for memories. Range: 0.2-0.8. Default: 0.6
- `summaries_threshold` (float): Similarity threshold for session summaries. Range: 0.2-0.8. Default: 0.5
- `last_n_messages` (int): Number of last messages to include in context. Range: 1-100. Optional
- `last_n_summaries` (int): Number of last summaries to include in context. Range: 1-20. Optional
- `timezone` (str): Timezone for formatting timestamps (e.g., 'America/New_York'). Default: UTC
- `include_system_prompt` (bool): Whether to include the default system prompt. Default: true
- `stream` (bool): Whether to stream status updates via Server-Sent Events. Default: false

**Returns:**
- When `stream=false`: JSON `GetContextResponse` with `is_final=true` and `context` field
- When `stream=true`: SSE stream of `GetContextResponse` events with progress updates, ending with a final event containing the context



## OpenAPI

````yaml https://api.recallrai.com/api/openapi.json get /api/v1/users/{custom_user_id}/sessions/{session_id}/context
openapi: 3.1.0
info:
  title: api-backend
  description: This powers the Recallr AI API Backend
  version: 0.1.0
servers:
  - url: https://api.recallrai.com
    description: Production server
security: []
paths:
  /api/v1/users/{custom_user_id}/sessions/{session_id}/context:
    get:
      tags:
        - Sessions
      summary: Get Context
      description: >-
        Retrieve AI context including relevant memories and recent
        conversations.


        Generate context for LLM prompts by retrieving the most relevant
        memories and recent messages

        for a user. Use this to manually inject memory context into your AI
        applications.


        **Path Parameters:**

        - `custom_user_id` (str): Unique identifier for the user

        - `session_id` (UUID): Session UUID to get context from


        **Query Parameters:**

        - `recall_strategy` (RecallStrategy): Memory retrieval strategy.
        Options: low_latency, balanced, agentic and auto. Default: balanced

        - `min_top_k` (int): Minimum number of memories to return. Range: 5-50.
        Default: 15

        - `max_top_k` (int): Maximum number of memories to return. Range:
        10-100. Default: 50

        - `memories_threshold` (float): Similarity threshold for memories.
        Range: 0.2-0.8. Default: 0.6

        - `summaries_threshold` (float): Similarity threshold for session
        summaries. Range: 0.2-0.8. Default: 0.5

        - `last_n_messages` (int): Number of last messages to include in
        context. Range: 1-100. Optional

        - `last_n_summaries` (int): Number of last summaries to include in
        context. Range: 1-20. Optional

        - `timezone` (str): Timezone for formatting timestamps (e.g.,
        'America/New_York'). Default: UTC

        - `include_system_prompt` (bool): Whether to include the default system
        prompt. Default: true

        - `stream` (bool): Whether to stream status updates via Server-Sent
        Events. Default: false


        **Returns:**

        - When `stream=false`: JSON `GetContextResponse` with `is_final=true`
        and `context` field

        - When `stream=true`: SSE stream of `GetContextResponse` events with
        progress updates, ending with a final event containing the context
      operationId: >-
        get_context_api_v1_users__custom_user_id__sessions__session_id__context_get
      parameters:
        - name: custom_user_id
          in: path
          required: true
          schema:
            type: string
            title: The custom user ID to get the context for
        - name: session_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: The session ID to get the context from
        - name: recall_strategy
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/RecallStrategy'
            title: The recall strategy to use
            default: auto
        - name: min_top_k
          in: query
          required: false
          schema:
            type: integer
            maximum: 50
            minimum: 5
            title: Minimum number of memories to return
            default: 15
        - name: max_top_k
          in: query
          required: false
          schema:
            type: integer
            maximum: 100
            minimum: 10
            title: Maximum number of memories to return
            default: 50
        - name: memories_threshold
          in: query
          required: false
          schema:
            type: number
            maximum: 0.8
            minimum: 0.2
            title: Similarity threshold for memories
            default: 0.6
        - name: summaries_threshold
          in: query
          required: false
          schema:
            type: number
            maximum: 0.8
            minimum: 0.2
            title: Similarity threshold for session summaries
            default: 0.5
        - name: last_n_messages
          in: query
          required: false
          schema:
            anyOf:
              - type: integer
                maximum: 100
                minimum: 1
              - type: 'null'
            title: Number of last messages to include in context
        - name: last_n_summaries
          in: query
          required: false
          schema:
            anyOf:
              - type: integer
                maximum: 20
                minimum: 1
              - type: 'null'
            title: Number of last summaries to include in context
        - name: timezone
          in: query
          required: false
          schema:
            type: string
            title: >-
              Timezone for formatting timestamps (e.g., 'America/New_York').
              Defaults to UTC.
            default: UTC
        - name: include_system_prompt
          in: query
          required: false
          schema:
            type: boolean
            title: Whether to include the default system prompt. Defaults to True
            default: true
        - name: stream
          in: query
          required: false
          schema:
            type: boolean
            title: >-
              Whether to stream status updates via Server-Sent Events. Defaults
              to False
            default: false
        - name: include_metadata_ids
          in: query
          required: false
          schema:
            type: boolean
            title: >-
              Whether to include memory IDs and session IDs that contributed to
              the context. Defaults to False
            default: false
        - name: X-Recallr-Project-Id
          in: header
          required: true
          schema:
            type: string
            format: uuid
            title: X-Recallr-Project-Id
        - name: X-Recallr-Api-Key
          in: header
          required: true
          schema:
            type: string
            title: X-Recallr-Api-Key
      responses:
        '200':
          description: Context retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetContextResponse'
              example:
                is_final: true
                context: '# Relevant memories and context.'
            text/event-stream:
              schema:
                type: string
                description: SSE data payload is JSON matching GetContextResponse.
                x-event-schema:
                  $ref: '#/components/schemas/GetContextResponse'
              example: >+
                data: {"is_final":false,"status_update_message":"Analyzing
                conversation..."}


                data: {"is_final":true,"context":"# Relevant memories."}

        '401':
          description: Authentication required
        '402':
          description: Payment required
        '404':
          description: Session not found
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '500':
          description: Internal server error
components:
  schemas:
    RecallStrategy:
      type: string
      enum:
        - low_latency
        - balanced
        - agentic
        - auto
      title: RecallStrategy
      description: Type of recall strategy.
    GetContextResponse:
      properties:
        is_final:
          type: boolean
          title: Is Final
        status_update_message:
          anyOf:
            - type: string
            - type: 'null'
          title: Status Update Message
        error_message:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Message
        context:
          anyOf:
            - type: string
            - type: 'null'
          title: Context
        metadata:
          anyOf:
            - $ref: '#/components/schemas/ContextMetadata'
            - type: 'null'
      type: object
      required:
        - is_final
      title: GetContextResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ContextMetadata:
      properties:
        memory_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Memory Ids
        session_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Session Ids
        agent_reasoning:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Reasoning
        vector_search_queries:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Vector Search Queries
        keywords:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Keywords
        session_summaries_search_queries:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Session Summaries Search Queries
        date_range_filters:
          anyOf:
            - items:
                $ref: '#/components/schemas/QueryDateRangeFilter'
              type: array
            - type: 'null'
          title: Date Range Filters
        recall_strategy_used:
          anyOf:
            - $ref: '#/components/schemas/RecallStrategy'
            - type: 'null'
      type: object
      title: ContextMetadata
      description: Metadata for context generation.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    QueryDateRangeFilter:
      properties:
        filter_type:
          $ref: '#/components/schemas/DateRangeFilterType'
        start_date:
          type: string
          format: date-time
          title: Start Date
        end_date:
          type: string
          format: date-time
          title: End Date
      type: object
      required:
        - filter_type
        - start_date
        - end_date
      title: QueryDateRangeFilter
      description: |-
        Represents a single date range filter extracted from user query.

        Examples:
            - "What did I mention last month?" -> start_date: 2025-12-01, end_date: 2025-12-31, filter_type: created_at
            - "What happened yesterday?" -> start_date: 2026-01-06, end_date: 2026-01-06, filter_type: event_date
    DateRangeFilterType:
      type: string
      enum:
        - event_date
        - created_at
      title: DateRangeFilterType
      description: Type of date field to filter on when querying memories.

````