{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/trajectory/main/json-schema/trajectory-trajectory-schema.json",
  "title": "Trajectory",
  "x-generated": "2026-10-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/trajectory-openapi.json#/components/schemas/Trajectory",
  "properties": {
    "trajectory_id": {
      "type": "string",
      "title": "Trajectory Id",
      "description": "Trajectory ID, returned as tid by the create endpoint."
    },
    "organization_id": {
      "type": "string",
      "title": "Organization Id"
    },
    "dataset_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Dataset Id"
    },
    "dataset_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Dataset Name"
    },
    "dataset_source": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Dataset Source"
    },
    "dataset_gcs_prefix": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Dataset Gcs Prefix"
    },
    "trace_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Trace Id"
    },
    "model_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Model Id"
    },
    "model_association_source": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Model Association Source"
    },
    "model_association_metadata": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "title": "Model Association Metadata"
    },
    "source": {
      "type": "string",
      "title": "Source"
    },
    "status": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Status"
    },
    "termination_reason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Termination Reason",
      "description": "Recorded reason the trajectory ended, independent of rollout state; null when not recorded."
    },
    "reward": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Reward"
    },
    "num_steps": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Num Steps"
    },
    "created_at": {
      "type": "string",
      "title": "Created At"
    },
    "training_run_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Training Run Id"
    },
    "xid": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Xid"
    },
    "task_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Task Id"
    },
    "policy_step": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Policy Step",
      "description": "Sampled policy step, not optimizer step."
    },
    "rollout": {
      "anyOf": [
        {
          "$ref": "#/$defs/TrajectoryRolloutStatus"
        },
        {
          "type": "null"
        }
      ]
    },
    "gcs_blob_uri": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Gcs Blob Uri"
    },
    "error": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Error"
    },
    "steps": {
      "items": {
        "$ref": "#/$defs/Step"
      },
      "type": "array",
      "title": "Steps"
    },
    "reward_components": {
      "items": {
        "$ref": "#/$defs/TrajectoryRewardComponent"
      },
      "type": "array",
      "title": "Reward Components",
      "description": "Logged reward components, in logged order."
    }
  },
  "type": "object",
  "required": [
    "trajectory_id",
    "organization_id",
    "source",
    "created_at"
  ],
  "$defs": {
    "HarnessDiagnostic": {
      "properties": {
        "exception_chain": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "maxItems": 4,
          "title": "Exception Chain",
          "default": []
        },
        "locations": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "maxItems": 4,
          "title": "Locations",
          "default": []
        },
        "category": {
          "type": "string",
          "enum": [
            "timeout",
            "connection",
            "rate_limit",
            "authentication",
            "server",
            "other"
          ],
          "title": "Category"
        },
        "preceding_tracebacks": {
          "items": {
            "$ref": "#/$defs/TracebackDiagnostic"
          },
          "type": "array",
          "maxItems": 4,
          "title": "Preceding Tracebacks",
          "default": []
        },
        "exit_code": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Exit Code"
        },
        "exception_messages": {
          "items": {
            "type": "string",
            "maxLength": 2048
          },
          "type": "array",
          "maxItems": 4,
          "title": "Exception Messages",
          "default": []
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "category"
      ],
      "title": "HarnessDiagnostic"
    },
    "ImagePart": {
      "properties": {
        "artifact_id": {
          "type": "string",
          "minLength": 1,
          "title": "Artifact Id",
          "description": "Image artifact attached to this trajectory. Use its artifact read endpoint to request a download URL."
        },
        "type": {
          "type": "string",
          "const": "image",
          "title": "Type",
          "description": "Identifies an image content part.",
          "default": "image"
        }
      },
      "type": "object",
      "required": [
        "artifact_id"
      ],
      "title": "ImagePart"
    },
    "Message": {
      "properties": {
        "message_id": {
          "type": "integer",
          "title": "Message Id"
        },
        "role": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Role"
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "items": {
                "anyOf": [
                  {
                    "$ref": "#/$defs/TextPart"
                  },
                  {
                    "$ref": "#/$defs/ImagePart"
                  }
                ]
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "title": "Content",
          "description": "Message text, an ordered list of text and image artifact references, or null."
        },
        "tool_calls": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Tool Calls"
        },
        "tool_response": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Tool Response"
        },
        "reasoning": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Reasoning"
        },
        "finish_reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Finish Reason"
        },
        "prompt_tokens": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Prompt Tokens"
        },
        "completion_tokens": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Completion Tokens"
        }
      },
      "type": "object",
      "required": [
        "message_id"
      ],
      "title": "Message"
    },
    "Step": {
      "properties": {
        "step_index": {
          "type": "integer",
          "title": "Step Index"
        },
        "reward": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Reward"
        },
        "has_error": {
          "type": "boolean",
          "title": "Has Error",
          "default": false
        },
        "messages": {
          "items": {
            "$ref": "#/$defs/Message"
          },
          "type": "array",
          "title": "Messages"
        }
      },
      "type": "object",
      "required": [
        "step_index"
      ],
      "title": "Step"
    },
    "TextPart": {
      "properties": {
        "text": {
          "type": "string",
          "title": "Text",
          "description": "Text at this position in the message content."
        },
        "type": {
          "type": "string",
          "const": "text",
          "title": "Type",
          "description": "Identifies a text content part.",
          "default": "text"
        }
      },
      "type": "object",
      "required": [
        "text"
      ],
      "title": "TextPart"
    },
    "TracebackDiagnostic": {
      "properties": {
        "exception_chain": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "maxItems": 4,
          "title": "Exception Chain",
          "default": []
        },
        "locations": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "maxItems": 4,
          "title": "Locations",
          "default": []
        }
      },
      "additionalProperties": false,
      "type": "object",
      "title": "TracebackDiagnostic"
    },
    "TrajectoryRewardComponent": {
      "properties": {
        "name": {
          "type": "string",
          "title": "Name",
          "description": "Reward component name."
        },
        "value": {
          "type": "number",
          "title": "Value",
          "description": "Raw value as logged."
        },
        "scaled_value": {
          "type": "number",
          "title": "Scaled Value",
          "description": "Value scaled to [0, 1]: (value - score_range_min) / (score_range_max - score_range_min)."
        },
        "weight": {
          "type": "number",
          "title": "Weight",
          "description": "Weight of this component in the logged reward."
        },
        "score_range_min": {
          "type": "number",
          "title": "Score Range Min"
        },
        "score_range_max": {
          "type": "number",
          "title": "Score Range Max"
        },
        "explanation": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Explanation"
        }
      },
      "type": "object",
      "required": [
        "name",
        "value",
        "scaled_value",
        "weight",
        "score_range_min",
        "score_range_max"
      ],
      "title": "TrajectoryRewardComponent"
    },
    "TrajectoryRolloutStatus": {
      "properties": {
        "rollout_id": {
          "type": "string",
          "title": "Rollout Id"
        },
        "status": {
          "type": "string",
          "title": "Status",
          "description": "Recorded Rollout Service state, such as IN_PROGRESS or FAILED."
        },
        "termination_reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Termination Reason",
          "description": "Recorded rollout termination enum."
        },
        "harness_diagnostic": {
          "anyOf": [
            {
              "$ref": "#/$defs/HarnessDiagnostic"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "type": "object",
      "required": [
        "rollout_id",
        "status"
      ],
      "title": "TrajectoryRolloutStatus"
    }
  }
}