PutTrace
Submits an agent's execution traces so that AWS Context can extract reusable knowledge and skills from them. Call it when an agent finishes a task or session that is worth learning from. In agentContextArns, name the agent contexts that the traces are about. AWS Context analyzes the traces for each of them.
Each traceDocuments entry is one raw trace document in the trace schema that format selects. You can send 1–100 documents per call. Each document can be up to 5 MiB before encoding. If you use an AWS SDK, pass each document's raw bytes. If you call PutTrace through the agent context's MCP server or another JSON client, send each document as a base64-encoded string. To send a larger trace, split it across calls that share a sessionId.
sessionId groups related calls into one session. If you omit it, AWS Context generates one and returns it in the response so that you can reuse it.
Each agent context can hold up to 100,000 trace documents. If a request would exceed this quota, it fails with ServiceQuotaExceededException, and AWS Context stores no documents. If a request fails for any other reason, AWS Context might have stored some of its documents. To store the rest without duplicates, retry with the same clientToken.
Request Parameters
- accessControlConfig
-
The principals who can see the insights that AWS Context generates from the traces. If you provide entries, the caller is not included unless an entry names it.
If you provide no entries (
accessControlConfigabsent, oraccessControlListabsent or empty), only the end user that the caller's trusted identity propagation session names can see the insights. If the session names no end user, or there is no session, the call fails withValidationExceptionand stores nothing. In that case, name the principals, or sendALLOWfor*so that every reader of the agent contexts can see the insights.An entry other than
*withoutprincipalType, aprincipalIdthat is not valid Unicode, or entries that total more than 65,536 bytes of UTF-8 are rejected withValidationException. AWS Context stores principal IDs as given and does not verify them against a directory. A session's access control is the union of its traces' entries. A call that would take that union over 100 entries, or over 65,536 bytes of UTF-8, fails withValidationExceptionand stores nothing.Type: AccessControlConfig object
Required: No
- agentContextArns
-
The ARNs of the agent contexts that the traces are about: 1–10
agent-context/ARNs that name at most 5 distinct agent contexts, in this Region and partition, all in your account. If you name more, the request fails withValidationException. AWS Context authorizescontext:PutTraceonce for each agent context. If any authorization is denied, the whole call fails withAccessDeniedException, and nothing is stored. After authorization, if trace analysis is disabled for an agent context, the call fails withValidationException, and nothing is stored.Type: Array of strings
Array Members: Minimum number of 1 item. Maximum number of 10 items.
Length Constraints: Minimum length of 1. Maximum length of 180.
Pattern:
arn:(aws|aws-cn|aws-us-gov):context:[a-z0-9\-]{1,32}:\d{12}:agent-context/[a-z0-9]+(-[a-z0-9]+)*Required: Yes
- clientToken
-
Makes the call idempotent. A retry with the same token and the same request returns the same
sessionIdand does not write the traces again. Reusing the token fails withValidationExceptionif the request is different, or if another caller reuses it whenaccessControlConfignames no entries. A token is honored for 8 hours after its first use. WhenaccessControlConfignames no entries and the caller's end user cannot be resolved at the time of the retry, the retry fails withValidationExceptioneven if the first attempt stored traces. To complete them, resend with explicit entries under a new token.Type: String
Length Constraints: Minimum length of 1. Maximum length of 64.
Pattern:
[\x21-\x7E]+Required: No
- format
-
The format of the documents in
traceDocuments. Valid values:-
OTEL- OpenTelemetry traces in OTLP/JSON. -
ANTHROPIC- Claude Code session logs, one log line per document. -
BEDROCK_CONVERSE- Amazon Bedrock Converse messages, one message (roleandcontent) per document, in conversation order. -
KIRO- Kiro IDE or Kiro CLI session logs.
Type: String
Valid Values:
OTEL | ANTHROPIC | BEDROCK_CONVERSE | KIRORequired: Yes
-
- sessionId
-
The agent session this trace belongs to and the grouping key: multiple PutTrace calls with the same
sessionIdare one session. Optional. If you omit it, the service generates one and returns it in the response. It is not thetraceId: an OTLP batch carries many trace_ids under one session.Type: String
Length Constraints: Minimum length of 1. Maximum length of 1024.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9_-]*Required: No
- traceDocuments
-
The raw trace documents, in the trace schema that
formatselects. You can send 1–100 documents per call, and each document can be up to 5 MiB (5,242,880 bytes) before encoding. If you use an AWS SDK, pass each document's raw bytes. If you call PutTrace through the agent context's MCP server or another JSON client, send each document as a base64-encoded string.Type: Array of Base64-encoded binary data objects
Array Members: Minimum number of 1 item. Maximum number of 100 items.
Length Constraints: Minimum length of 1. Maximum length of 5242880.
Required: Yes
- traceMetadata
-
Client-supplied key-value pairs, stored with the traces as-is. The key
analysisModeis reserved. A request that sets it fails withAccessDeniedException.Type: String to string map
Map Entries: Minimum number of 0 items. Maximum number of 50 items.
Key Length Constraints: Minimum length of 1. Maximum length of 128.
Value Length Constraints: Minimum length of 0. Maximum length of 1024.
Required: No
Response Elements
The following element is returned by the service.
- sessionId
-
The session ID for the traces: the
sessionIdthat you specified, or one that AWS Context generated if you omitted it. A successful response means that AWS Context stored every document. A failed call might leave some documents stored. To store the rest without duplicates, retry with the sameclientToken.Type: String
Length Constraints: Minimum length of 1. Maximum length of 1024.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9_-]*
Errors
For information about the errors that are common to all actions, see Common Error Types.
- AccessDeniedException
-
You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.
- message
-
A message that describes the error.
HTTP Status Code: 403
- ConflictException
-
The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.
- message
-
A message that describes the error.
- resourceId
-
The ID of the resource that caused the conflict. When several resources caused it, a comma-separated list of their IDs.
- resourceType
-
The type of the resource that caused the conflict.
Valid values:
-
agent-context- An agent context. -
connection- A connection. -
curation-policy- A curation policy. -
evaluation- Reserved for future use. -
ontology- An ontology. -
ontology-induction- An ontology induction. -
resource-policy- A resource-based policy.
-
HTTP Status Code: 409
- InternalServerException
-
The request failed because of an internal error. Retry the request.
- message
-
A message that describes the error.
HTTP Status Code: 500
- ResourceNotFoundException
-
The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.
- message
-
A message that describes the error.
- resourceId
-
The ID of the resource that was not found.
- resourceType
-
The type of the resource that wasn't found.
Valid values:
-
agent-context- An agent context. -
connection- A connection. -
curation-policy- A curation policy. -
evaluation- Reserved for future use. -
ontology- An ontology. -
ontology-induction- An ontology induction. -
resource-policy- A resource-based policy.
-
HTTP Status Code: 404
- ServiceQuotaExceededException
-
The request would exceed a service quota. Check the quota that
quotaCodenames, reduce your usage, and then retry the request.- message
-
A message that describes the error.
- quotaCode
-
The code of the quota that the request would exceed.
- resourceId
-
The ID of the resource that the quota applies to.
- resourceType
-
The type of the resource that the quota applies to.
Valid values:
-
agent-context- An agent context. -
connection- A connection. -
curation-policy- A curation policy. -
evaluation- Reserved for future use. -
ontology- An ontology. -
ontology-induction- An ontology induction. -
resource-policy- A resource-based policy.
-
- serviceCode
-
The code of the service that owns the quota.
HTTP Status Code: 402
- ThrottlingException
-
The request was denied because it exceeded a request rate quota. Wait, then retry the request.
- message
-
A message that describes the error.
- quotaCode
-
The code of the quota that throttled the request.
- retryAfterSeconds
-
The number of seconds to wait before you retry the request, if AWS Context provides one.
- serviceCode
-
The code of the service whose quota throttled the request.
HTTP Status Code: 429
- ValidationException
-
The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.
- fieldList
-
The fields that failed validation, each with a message that describes why.
- message
-
A message that describes the error.
- reason
-
The reason that the input failed validation. Valid values:
-
unknownOperation- The operation isn't recognized. -
cannotParse- The request couldn't be parsed. -
fieldValidationFailed- One or more fields failed validation.fieldListdescribes them. -
other- Another reason.messagedescribes it.
-
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: