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
| Method | Description |
|---|---|
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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| user_id | int | Yes | -- | Target customer id (positional argument) |
| enabled | bool | Yes | -- | True to enable recording, False to disable (positional argument) |
Response
Returns bool — True on success.
Errors
| Code | Exception | When |
|---|---|---|
2007 | PermissionError | Admin lacks Context Management permission |
3001 | AuthenticationError | Session 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| user_id | int | Yes | -- | Target customer id |
| start_date | str | No | -- | Range start (YYYY-MM-DD) |
| end_date | str | No | -- | Range end (YYYY-MM-DD) |
| trace_id_filter | str | No | -- | Filter by trace id |
| api_key_id | int | No | -- | Filter by API key id |
| max_traces | int | No | -- | Max traces to return |
Response
Returns a dict with entries, totalEntries, totalBytes, truncated.
Errors
| Code | Exception | When |
|---|---|---|
2007 | PermissionError | Admin lacks Context Management permission |
3001 | AuthenticationError | Session 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| uid | int | Yes | -- | Target customer id |
| partition_date | str | Yes | -- | Record partition date (YYYY-MM-DD) |
| trace_id | str | Yes | -- | Trace id of the record |
| visibility | str | Yes | -- | Record visibility scope |
Response
Returns a dict with traceId, uid, visibility, inputJson, outputJsonl.
Errors
| Code | Exception | When |
|---|---|---|
2007 | PermissionError | Admin lacks Context Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
| Server 4xx | WltError | No record matches the given trace_id / partition_date |