Skip to main content

Admin Context — Python SDK

Context-record toggle, listing, and body export for a customer.

Overview​

The admin Context resource controls context recording for an end-customer and exports recorded entries. Toggle recording on or off, list recorded entries within a date range, and fetch the input/output payload of a single record.

Accessed via admin.context.

Available Operations​

MethodDescription
toggle()Enable or disable context recording for a customer
list()List recorded context entries within a date range
get_body()Fetch a single record's input/output payload

toggle​

Enable or disable context recording for a customer.

Example Usage​

ok = admin.context.toggle(user_id=42, enabled=True)
print(ok) # True

# Turn it back off
admin.context.toggle(user_id=42, enabled=False)

Parameters​

ParameterTypeRequiredDefaultDescription
user_idintYes--Target customer id (positional argument)
enabledboolYes--True to enable recording, False to disable (positional argument)

Response​

Returns bool — True on success.

Errors​

CodeExceptionWhen
2007PermissionErrorAdmin lacks Context Management permission
3001AuthenticationErrorSession expired and refresh failed

list​

List recorded context entries for a customer, optionally filtered by date range, trace id, or API key id.

Example Usage​

result = admin.context.list(
user_id=42,
start_date="2026-07-01",
end_date="2026-07-14",
)
print(result["totalEntries"], result["totalBytes"], result["truncated"])
for entry in result["entries"]:
print(entry)

Parameters​

ParameterTypeRequiredDefaultDescription
user_idintYes--Target customer id
start_datestrNo--Range start (YYYY-MM-DD)
end_datestrNo--Range end (YYYY-MM-DD)
trace_id_filterstrNo--Filter by trace id
api_key_idintNo--Filter by API key id
max_tracesintNo--Max traces to return

Response​

Returns a dict with entries, totalEntries, totalBytes, truncated.

Errors​

CodeExceptionWhen
2007PermissionErrorAdmin lacks Context Management permission
3001AuthenticationErrorSession expired and refresh failed

get_body​

Fetch a single recorded context body (input/output payload).

Example Usage​

body = admin.context.get_body(
uid=42,
partition_date="2026-07-14",
trace_id="trace-abc",
visibility="PLATFORM",
)
print(body["inputJson"])
print(body["outputJsonl"])

Parameters​

ParameterTypeRequiredDefaultDescription
uidintYes--Target customer id
partition_datestrYes--Record partition date (YYYY-MM-DD)
trace_idstrYes--Trace id of the record
visibilitystrYes--Record visibility scope

Response​

Returns a dict with traceId, uid, visibility, inputJson, outputJsonl.

Errors​

CodeExceptionWhen
2007PermissionErrorAdmin lacks Context Management permission
3001AuthenticationErrorSession expired and refresh failed
Server 4xxWltErrorNo record matches the given trace_id / partition_date