startCodeInterpreterSession method
Creates and initializes a code interpreter session in Amazon Bedrock AgentCore. The session enables agents to execute code as part of their response generation, supporting programming languages such as Python for data analysis, visualization, and computation tasks.
To create a session, you must specify a code interpreter identifier and a
name. The session remains active until it times out or you explicitly stop
it using the StopCodeInterpreterSession operation.
The following operations are related to
StartCodeInterpreterSession:
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter codeInterpreterIdentifier :
The unique identifier of the code interpreter to use for this session.
This identifier specifies which code interpreter environment to initialize
for the session.
Parameter certificates :
A list of certificates to install in the code interpreter session.
Parameter clientToken :
A unique, case-sensitive identifier to ensure that the API request
completes no more than one time. If this token matches a previous request,
Amazon Bedrock AgentCore ignores the request, but does not return an
error. This parameter helps prevent the creation of duplicate sessions if
there are temporary network issues.
Parameter name :
The name of the code interpreter session. This name helps you identify and
manage the session. The name does not need to be unique.
Parameter sessionTimeoutSeconds :
The duration in seconds (time-to-live) after which the session
automatically terminates, regardless of ongoing activity. Defaults to 900
seconds (15 minutes). Recommended minimum: 60 seconds. Maximum allowed:
28,800 seconds (8 hours).
Parameter traceId :
The trace identifier for request tracking.
Parameter traceParent :
The parent trace information for distributed tracing.
Implementation
Future<StartCodeInterpreterSessionResponse> startCodeInterpreterSession({
required String codeInterpreterIdentifier,
List<Certificate>? certificates,
String? clientToken,
String? name,
int? sessionTimeoutSeconds,
String? traceId,
String? traceParent,
}) async {
_s.validateNumRange(
'sessionTimeoutSeconds',
sessionTimeoutSeconds,
1,
28800,
);
final headers = <String, String>{
if (traceId != null) 'X-Amzn-Trace-Id': traceId.toString(),
if (traceParent != null) 'traceparent': traceParent.toString(),
};
final $payload = <String, dynamic>{
if (certificates != null) 'certificates': certificates,
'clientToken': clientToken ?? _s.generateIdempotencyToken(),
if (name != null) 'name': name,
if (sessionTimeoutSeconds != null)
'sessionTimeoutSeconds': sessionTimeoutSeconds,
};
final response = await _protocol.send(
payload: $payload,
method: 'PUT',
requestUri:
'/code-interpreters/${Uri.encodeComponent(codeInterpreterIdentifier)}/sessions/start',
headers: headers,
exceptionFnMap: _exceptionFns,
);
return StartCodeInterpreterSessionResponse.fromJson(response);
}