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

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

The generated resource methods map directly to the public HTTP API. Benchmark submission and file-upload workflows are available from trajectory.lib. Detailed authored guides are not currently available without documentation access; the core workflow is included here.

Native benchmark harness

A task's run_command starts your program inside its runtime. Supply task input through TaskSpec.env_vars, such as QUESTION and EXPECTED_ANSWER below. 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_BASE_URL, TRAJECTORY_TOKEN, and model-endpoint credentials. Use Client() without embedding API keys in the image. MODEL_ENDPOINT_ACCESS_TOKEN makes trajectories.create() resolve the precreated trajectory and authenticates model requests. The SDK does not read TRAJECTORY_TID; pass the returned ID explicitly to related calls. Outside a managed run, configure TRAJECTORY_API_KEY and a model endpoint for model access.

import os

from trajectory import Client

client = Client()
tid = client.trajectories.create().tid
try:
    response = client.chat.completions.create(
        model="policy",
        messages=[{"role": "user", "content": os.environ["QUESTION"]}],
        extra_headers={"X-Trajectory-Id": tid},
    )
    answer = response.choices[0].message.content or ""
    reward = float(answer.strip() == os.environ["EXPECTED_ANSWER"])
    client.trajectories.log_reward(tid, reward_id="answer", name="accuracy", value=reward)
except Exception as error:
    try:
        client.trajectories.complete(tid, termination_reason="ERROR")
    except Exception as completion_error:
        error.add_note(f"Error completion failed: {type(completion_error).__name__}")
    raise
else:
    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; a model or grader error remains an error, even if reporting its completion also fails. 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, register it and build its runtime:

from pathlib import Path

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

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

push() uploads files and waits for task registration; it does not start image builds. 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, use the benchmark ID to start evaluation or training; uploading does not execute the tasks. 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

Release files for trajectory-sdk 0.6.23

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.6.23
File Size Uploaded
trajectory_sdk-0.6.23.tar.gz 87.8 kB Details

Built distribution (wheel)

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

Total release size: 252.2 kB

Release files / trajectory_sdk-0.6.23.tar.gz

Download URL trajectory_sdk-0.6.23.tar.gz
Size 87.8 kB
Tags Source
SHA-256 checksum
How to use checksums
da274edc71347cb3fbe76f7128a3ff4616684c7c1157120453c94a486c37bb42
BLAKE2b-256 checksum
How to use checksums
40820a4dc8b7cb745a38bd39da0a4a1091a0eca83e2a1a8db74c519ba0eee7f2
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 Sep 24, 2026.

Transparency log

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

Download URL trajectory_sdk-0.6.23-py3-none-any.whl
Size 164.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab94b20316985df59ada58c09c7ce18cb34833b44a47ded9f70613ad0c534874
BLAKE2b-256 checksum
How to use checksums
014131271a705ef487528d1d27774f9bed443e8fa9df6b3f675117aa09e6cdc9
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 Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

0.6.26

2 release files

0.6.25

2 release files

0.6.24

2 release files

This release

0.6.23 This release

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