Skip to main content

Get Started

trajectory is a SDK that helps you with everything post-building. You can use it to trace, capture user metrics, create custom monitors and run evaluations on your agents. We are working on getting the feature of dataset creation very very soon. trajectory is built and maintained by trajectory.ai.

Get your free trajectory API keys

Head to the trajectory and create an account. Then, copy your API key into your environment variables.
export TRAJECTORY_API_KEY="your_key_here"
1

Install trajectory

  • Tab Title
pip install trajectoryeval
2

Start tracing with trajectory

Below is a minimal example that instruments a small function and an LLM call. You’ll see both the function and the tool step show up as spans in your trace.
trace.py
from trajectory import Tracer, wrap
from openai import OpenAI

# Wrap your OpenAI client so model calls are captured as spans
client = wrap(OpenAI())

# Initialize a tracer to group spans into a single trace
tracer = Tracer(project_name="default_project")

# Mark helper utilities as tools
@tracer.observe(span_type="tool")
def format_currency(n: float) -> str:
    return f"${n:,.2f}"

# Your application logic — captured as a function span
@tracer.observe(name="plan_trip", span_type="function")
def plan_trip(city: str) -> str:
    prompt = f"Plan a 1-day itinerary for {city}. Budget: {format_currency(120)}."
    resp = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": prompt}],
    )
    return resp.choices[0].message.content

if __name__ == "__main__":
    plan_trip("Lisbon")
Congratulations! You’ve just created your first trace.

Next Steps

We provide two things: tracing and evaluation. Explore each area below.