> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trajectory.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Keep diagnostic files with a trajectory

> Attach task logs and reports without changing the reward.

Use `log_event` for structured JSON and artifacts for files such as test logs or reports.
Write events and finish uploads before completing the trajectory. A distinct event needs a
distinct `event_id`; reuse an ID only when retrying the same write, because an existing ID
is deduplicated rather than updated. Read events with `client.trajectories.list_events(tid)`.

An artifact upload can contain at most 16 MiB. Compress larger text reports or split them
into files. With an active trajectory ID `tid`, upload a compressed report:

```python theme={null}
import base64
import gzip
import hashlib
import urllib.request
from pathlib import Path

from trajectory import Client

client = Client()
content = gzip.compress(Path("report.json").read_bytes(), mtime=0)
upload = client.trajectories.artifacts.create_upload(
    tid,
    media_type="application/gzip",
    size_bytes=len(content),
    md5=base64.b64encode(hashlib.md5(content, usedforsecurity=False).digest()).decode(),
)
request = urllib.request.Request(
    upload.upload_url, data=content, headers=upload.headers, method="PUT"
)
urllib.request.urlopen(request, timeout=120).close()
artifact = client.trajectories.artifacts.complete_upload(tid, upload.artifact_id)
client.trajectories.log_event(
    tid,
    event_id="diagnostic-report",
    name="diagnostic_report",
    payload={"artifact_id": artifact.artifact_id, "filename": "report.json.gz"},
)
```

`complete_upload` attaches the file to the trajectory. Later, call
`client.artifacts.retrieve(artifact.artifact_id)` and download its `download_url`.
Report an upload failure separately from the task's execution result and computed reward.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.