> ## 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.

# Collect production traces

> Private beta: record model calls and outcomes from your application.

> [!NOTE]
>
> Private beta. For runnable tasks and a grader, start with [specs (benchmarks)](https://docs.trajectory.ai/guides/spec.md).

A production trace belongs to an [agent](https://docs.trajectory.ai/concepts.md). Your application creates a trajectory, sends model calls through Trajectory, and marks it complete.

```python theme={null}
from trajectory import Client

request_id = "request-example-001"

with Client() as client:
    session = client.trajectories.create(
        body={"agent_id": "<agent-id>"},
        idempotency_key=request_id,
    )

    response = client.chat.completions.create(
        model="<serving-model-name>",
        x_trajectory_id=session.tid,
        messages=[
            {"role": "system", "content": "Return only the numeric answer."},
            {"role": "user", "content": "What is 19 times 23?"},
        ],
    )

    answer = response.choices[0].message.content

    client.trajectories.log_reward(
        session.tid,
        name="answer_correct",
        value=float(answer is not None and answer.strip() == "437"),
        explanation="Exact match against the expected answer, 437.",
    )
    client.trajectories.complete(
        session.tid,
        termination_reason="ENV_DONE",
    )
```

Replace the agent, model, and grader with yours. Reuse `idempotency_key` when retrying the same request. The organization key authenticates creation, model calls, rewards, and completion. Pass the returned `tid` explicitly to each trajectory operation.

Log a reward when you have a grader. Otherwise complete the trajectory and attach later events with [telemetry](https://docs.trajectory.ai/guides/telemetry.md).


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