Skip to main content

Trajectory SDK

Generated Python client for the Trajectory API, with high-level workflows for uploading trajectories, telemetry, and runtime-backed benchmarks.

Install

pip install trajectory-sdk

Start here

Follow the public SDK onboarding guide to run one T Factory task and see its response, recorded reward, and completion. Continue with the GSM8K walkthrough: diagnose one task, evaluate and train with one task per split, then upload the larger benchmark and diagnose a subset before training. Evaluation and training use agent and benchmark names. The cookbook's example guide explains which recipe to use next for your benchmark's harness and grader.

Quick start

Set TRAJECTORY_API_KEY, then create a client:

from trajectory import Client

client = Client()
benchmarks = client.benchmarks.list(limit=10)

For task execution, follow the native benchmark harness and registration and image builds examples below.

SDK-owned API clients use a 600-second read/write/pool timeout and a 5-second connection timeout. Supplying http_client= inherits that client's timeouts, including a bare HTTPX client's 5-second default. An explicit Client(timeout=...) overrides the supplied client; a resource method's timeout= overrides that request. timeout=None disables timeouts. Retry counts are unchanged.

Blob store uploads through signed URLs default to a one-hour timeout (3,600 seconds), configured separately from API requests. Set upload_timeout=... on push(), start_push(), or start_task_diagnostic(), or timeout=... on put_files(). Pass None to disable blob store timeouts. These apply to individual HTTP operations against the blob store, not the total upload duration or signed-URL expiry.

The generated resource methods map directly to the public HTTP API. Benchmark submission and file-upload workflows are available from trajectory.lib.

Native benchmark harness

A task's run_command starts your program inside its runtime. This self-contained example uses an inline question and expected answer for clarity. Inputs and references may come from files or other sources; ensure the agent and its tools cannot access private reference data. input_messages is stored task metadata; the native runtime does not send it to the model or to your program's stdin. Your harness reads the input, calls the model, grades its answer, records the reward, and completes the trajectory before exiting. The SDK has no trajectory CLI executable.

Managed runs supply TRAJECTORY_API_KEY and TRAJECTORY_BASE_URL. Use Client() without embedding credentials in the image. trajectories.create() returns the precreated trajectory ID; pass that ID explicitly to model, reward, and completion calls. Model requests use the same client and API key, while the Backend resolves the model endpoint.

from trajectory import Client

client = Client()
question = "What is 2 + 2?"
expected_answer = "4"

tid = client.trajectories.create().tid

response = client.chat.completions.create(
    model="policy",
    messages=[{"role": "user", "content": question}],
    x_trajectory_id=tid,
)

model_answer = response.choices[0].message.content or ""
reward = float(model_answer.strip() == expected_answer)

client.trajectories.log_reward(
    tid,
    name="accuracy",
    value=reward,
)
client.trajectories.complete(tid, termination_reason="ENV_DONE")

Package this file and its dependencies in your Dockerfile. For example, copying it to /app/harness.py makes python /app/harness.py the task's run_command. A wrong answer gets reward zero and ENV_DONE. Process exit alone does not complete a trajectory.

Registration and image builds

Define a BenchmarkSpec named benchmark with your tasks, distinct train/test splits, and a runtime such as DockerfileBuild("Dockerfile"). With the Dockerfile and harness under the local benchmark/ directory, choose or create an agent, then register the benchmark and build its runtime. Replace YOUR_AGENT_NAME with that agent's name:

from pathlib import Path

from trajectory import Client
from trajectory.lib import push, wait_for_benchmark_images

client = Client()
result = push(client, benchmark, agent_name="YOUR_AGENT_NAME", root=Path("benchmark"))
images = wait_for_benchmark_images(client, result.bench_id)

The benchmark name comes from manifest.name: reusing a name under the same agent pushes a new version. Every new submission returns a new benchmark ID. Uploads do not accept a benchmark ID.

push() calls start_push() and waits for registration, returning a benchmark result with bench_id. Both upload files with progress and accept the same arguments. Image builds are off by default; pass build_images=True to include them.

Use start_push() when you want control over waiting: it uploads files before returning a BenchmarkOperation, while server processing continues. Call operation.result() to wait, or save operation.id and reconnect later with get_operation(client, operation.id). It is a regular Python function; it does not require await.

wait_for_benchmark_images() first calls client.benchmarks.images.build(bench_id) and then polls for completion. client.benchmarks.images.list(bench_id) only reads status. Once the runtime is ready, follow the GSM8K walkthrough's validation and evaluation steps; uploading does not execute the tasks. Start evaluation or training with agent_name and benchmark_name to select the latest version, or bench_id to select a specific version. Run this registration code with your organization's API key.

Development

uv run pytest
uv run ruff check .
uv run ruff format --check .

The generated client lives in src/trajectory/. Handwritten workflows live in src/trajectory/lib/, and tests live in tests/.

License

Apache 2.0

Metadata

Release files for trajectory-sdk 0.9.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trajectory-sdk 0.9.15
File Size Uploaded
trajectory_sdk-0.9.15.tar.gz 160.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trajectory-sdk 0.9.15
File Interpreter ABI Platform
trajectory_sdk-0.9.15-py3-none-any.whl Python 3 none any Details

Total release size: 414.2 kB

Release files / trajectory_sdk-0.9.15.tar.gz

Download URL trajectory_sdk-0.9.15.tar.gz
Size 160.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1b2233b5cd36e588ead52671ad057448f76f8016a7b564d6523a9fec566da4de
BLAKE2b-256 checksum
How to use checksums
7c58e51bd90928c4821f2e0fdbea847135bd41f497648f49278baa19fde25277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release files / trajectory_sdk-0.9.15-py3-none-any.whl

Download URL trajectory_sdk-0.9.15-py3-none-any.whl
Size 253.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d0bdc8f2b80a53f16cd77d04bfb65a38ccd6954b96bd548e0a7066cc6f78ed2
BLAKE2b-256 checksum
How to use checksums
6ddf3cf3ea66755aa1ddcfa78c8d606d40362bf583dc92efb5e0e32734164fe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.21

2 release files

0.9.20

2 release files

0.9.19

2 release files

0.9.18

2 release files

0.9.17

2 release files

0.9.16

2 release files

This release

0.9.15 This release

2 release files

0.7.21

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.26

2 release files

0.6.25

2 release files

0.6.24

2 release files

0.6.23

2 release files

0.6.22

2 release files

0.6.21

2 release files

0.6.20

2 release files

0.6.19

2 release files

0.6.18

2 release files

0.6.17

2 release files

0.6.16

2 release files

0.6.15

2 release files

0.6.14

2 release files

0.6.13

2 release files

0.6.12

2 release files

0.6.11

2 release files

0.6.10

2 release files

0.6.9

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page