:doc:`AgentsforBedrockRuntime <../../bedrock-agent-runtime>` / Client / create_session

**************
create_session
**************



.. py:method:: AgentsforBedrockRuntime.Client.create_session(**kwargs)

  

  Creates a session to temporarily store conversations for generative AI (GenAI) applications built with open-source frameworks such as LangGraph and LlamaIndex. Sessions enable you to save the state of conversations at checkpoints, with the added security and infrastructure of Amazon Web Services. For more information, see `Store and retrieve conversation history and context with Amazon Bedrock sessions <https://docs.aws.amazon.com/bedrock/latest/userguide/sessions.html>`__.

   

  By default, Amazon Bedrock uses Amazon Web Services-managed keys for session encryption, including session metadata, or you can use your own KMS key. For more information, see `Amazon Bedrock session encryption <https://docs.aws.amazon.com/bedrock/latest/userguide/session-encryption.html>`__.

   

  .. note::

    

    You use a session to store state and conversation history for generative AI applications built with open-source frameworks. For Amazon Bedrock Agents, the service automatically manages conversation context and associates them with the agent-specific sessionId you specify in the `InvokeAgent <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html>`__ API operation.

    

   

  Related APIs:

   

  
  * `ListSessions <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ListSessions.html>`__
   
  * `GetSession <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_GetSession.html>`__
   
  * `EndSession <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_EndSession.html>`__
   
  * `DeleteSession <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_DeleteSession.html>`__
  

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/bedrock-agent-runtime-2023-07-26/CreateSession>`_  


  **Request Syntax**
  ::

    response = client.create_session(
        encryptionKeyArn='string',
        sessionMetadata={
            'string': 'string'
        },
        tags={
            'string': 'string'
        }
    )
    
  :type encryptionKeyArn: string
  :param encryptionKeyArn: 

    The Amazon Resource Name (ARN) of the KMS key to use to encrypt the session data. The user or role creating the session must have permission to use the key. For more information, see `Amazon Bedrock session encryption <https://docs.aws.amazon.com/bedrock/latest/userguide/session-encryption.html>`__.

    

  
  :type sessionMetadata: dict
  :param sessionMetadata: 

    A map of key-value pairs containing attributes to be persisted across the session. For example, the user's ID, their language preference, and the type of device they are using.

    

  
    - *(string) --* 

    
      - *(string) --* 

      


  :type tags: dict
  :param tags: 

    Specify the key-value pairs for the tags that you want to attach to the session.

    

  
    - *(string) --* 

      Key of a tag

      

    
      - *(string) --* 

        Value of a tag

        

      


  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {
          'createdAt': datetime(2015, 1, 1),
          'sessionArn': 'string',
          'sessionId': 'string',
          'sessionStatus': 'ACTIVE'|'EXPIRED'|'ENDED'
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **createdAt** *(datetime) --* 

        The timestamp for when the session was created.

        
      

      - **sessionArn** *(string) --* 

        The Amazon Resource Name (ARN) of the created session.

        
      

      - **sessionId** *(string) --* 

        The unique identifier for the session.

        
      

      - **sessionStatus** *(string) --* 

        The current status of the session.

        
  
  **Exceptions**
  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ConflictException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ValidationException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.InternalServerException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ThrottlingException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.AccessDeniedException`

  
  *   :py:class:`AgentsforBedrockRuntime.Client.exceptions.ServiceQuotaExceededException`

  