

# 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
<a name="API_PutTrace_RequestParameters"></a>

 ** 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 (`accessControlConfig` absent, or `accessControlList` absent 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 with `ValidationException` and stores nothing. In that case, name the principals, or send `ALLOW` for `*` so that every reader of the agent contexts can see the insights.  
An entry other than `*` without `principalType`, a `principalId` that is not valid Unicode, or entries that total more than 65,536 bytes of UTF-8 are rejected with `ValidationException`. 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 with `ValidationException` and stores nothing.  
Type: [AccessControlConfig](API_AccessControlConfig.md) 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 with `ValidationException`. AWS Context authorizes `context:PutTrace` once for each agent context. If any authorization is denied, the whole call fails with `AccessDeniedException`, and nothing is stored. After authorization, if trace analysis is disabled for an agent context, the call fails with `ValidationException`, 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 `sessionId` and does not write the traces again. Reusing the token fails with `ValidationException` if the request is different, or if another caller reuses it when `accessControlConfig` names no entries. A token is honored for 8 hours after its first use. When `accessControlConfig` names no entries and the caller's end user cannot be resolved at the time of the retry, the retry fails with `ValidationException` even 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 (`role` and `content`) per document, in conversation order.
+  `KIRO` - Kiro IDE or Kiro CLI session logs.
Type: String  
Valid Values: `OTEL | ANTHROPIC | BEDROCK_CONVERSE | KIRO`   
Required: Yes

 ** sessionId **   
The agent session this trace belongs to and the grouping key: multiple PutTrace calls with the same `sessionId` are one session. Optional. If you omit it, the service generates one and returns it in the response. It is not the `traceId`: 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 `format` selects. 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 `analysisMode` is reserved. A request that sets it fails with `AccessDeniedException`.  
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
<a name="API_PutTrace_ResponseElements"></a>

The following element is returned by the service.

 ** sessionId **   
The session ID for the traces: the `sessionId` that 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 same `clientToken`.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 1024.  
Pattern: `[a-zA-Z0-9][a-zA-Z0-9_-]*` 

## Errors
<a name="API_PutTrace_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** 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 `quotaCode` names, 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. `fieldList` describes them.
+  `other` - Another reason. `message` describes it.
HTTP Status Code: 400

## See Also
<a name="API_PutTrace_SeeAlso"></a>

For more information about using this API in one of the language-specific AWS SDKs, see the following:
+  [AWS Command Line Interface V2](https://docs.aws.amazon.com/goto/cli2/context-2022-07-26/PutTrace) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/context-2022-07-26/PutTrace) 
+  [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/context-2022-07-26/PutTrace) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/context-2022-07-26/PutTrace) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/context-2022-07-26/PutTrace) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/context-2022-07-26/PutTrace) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/context-2022-07-26/PutTrace) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/context-2022-07-26/PutTrace) 
+  [AWS SDK for Python (Boto3)](https://docs.aws.amazon.com/goto/boto3/context-2022-07-26/PutTrace) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/context-2022-07-26/PutTrace) 