createSession method

Future<CreateSessionResponse> createSession({
  1. String? encryptionKeyArn,
  2. Map<String, String>? sessionMetadata,
  3. Map<String, String>? tags,
})

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.

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. Related APIs:

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter 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.

Parameter 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.

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

Implementation

Future<CreateSessionResponse> createSession({
  String? encryptionKeyArn,
  Map<String, String>? sessionMetadata,
  Map<String, String>? tags,
}) async {
  final $payload = <String, dynamic>{
    if (encryptionKeyArn != null) 'encryptionKeyArn': encryptionKeyArn,
    if (sessionMetadata != null) 'sessionMetadata': sessionMetadata,
    if (tags != null) 'tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'PUT',
    requestUri: '/sessions/',
    exceptionFnMap: _exceptionFns,
  );
  return CreateSessionResponse.fromJson(response);
}