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

# Set (upsert) the stored context for a chat session

> Stores a free-text background string for the given session. The value is encrypted at rest and injected into the agent system prompt on every subsequent chat turn. Auto-creates the end_user record if it does not yet exist. Replaces any previously stored context.



## OpenAPI

````yaml /api-reference/openapi.json put /chat-sessions/{sessionId}/context
openapi: 3.0.0
info:
  title: RouteMCP API
  description: >-
    Unified API for integrations. Connect to multiple providers through a single
    API.
  version: '1.0'
  contact: {}
servers:
  - url: https://api.routemcp.io/api/v1
    description: Production
security:
  - bearerAuth: []
tags: []
paths:
  /chat-sessions/{sessionId}/context:
    put:
      tags:
        - HTTP Streaming Chat
      summary: Set (upsert) the stored context for a chat session
      description: >-
        Stores a free-text background string for the given session. The value is
        encrypted at rest and injected into the agent system prompt on every
        subsequent chat turn. Auto-creates the end_user record if it does not
        yet exist. Replaces any previously stored context.
      operationId: ChatSessionContextController_setContext
      parameters:
        - name: sessionId
          in: path
          required: true
          description: UUID of the chat session whose context you want to set.
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - context
              properties:
                context:
                  type: string
                  maxLength: 50000
                  description: >-
                    Free-text background stored (encrypted, sticky) for this
                    chat session and injected into the agent on each turn. Empty
                    string stores empty; use DELETE to remove.
      responses:
        '200':
          description: Context upserted successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  context:
                    type: string
                  updatedAt:
                    type: string
                    format: date-time
        '400':
          description: >-
            Bad Request — invalid sessionId UUID or context exceeds 50000
            characters.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    example: false
                  statusCode:
                    type: integer
                    example: 400
                    default: 400
                  message:
                    type: string
                    example: sessionId must be a valid UUID
                    default: Bad Request
                  timestamp:
                    type: string
                    format: date-time
                    example: '2026-02-06T12:00:00.000Z'
                  path:
                    type: string
                    example: /api/v1/chat-sessions/<id>/context
                required:
                  - success
                  - statusCode
                  - message
                  - timestamp
                  - path
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Enter your API key with the Bearer prefix — e.g. Bearer sk_live_xxx
        (production) or Bearer sk_test_xxx (sandbox)

````