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

# Add Dataset Trajectories

> Add a training/eval run's trajectories to a draft dataset. Poll the returned operation.



## OpenAPI

````yaml /openapi.json post /api/v1/datasets/{dataset_id}/trajectories
openapi: 3.1.0
info:
  title: Trajectory API
  version: 0.1.0
  x-trajectory-api-version: '2026-10-14'
  description: >-
    This contract is API version 2026-10-14. The optional Trajectory-API-Version
    header pins it, and tmp-contract is accepted as an alias. Requests without
    the header get this version. Version 2026-10-07 and the pre-launch legacy
    response formats are retired.
servers:
  - url: https://api.trajectory.ai
security: []
tags:
  - name: projects
    x-group: Projects
  - name: specs
    x-group: Specs
  - name: diagnostics
    x-group: Diagnostics
  - name: spec-ingestion
    x-group: Spec submissions
  - name: spec-findings
    x-group: Spec findings
  - name: eval
    x-group: Evaluations
  - name: training
    x-group: Training
  - name: deployments
    x-group: Deployments
  - name: model-endpoints
    x-group: Model endpoints
  - name: inference
    x-group: Inference
  - name: trajectories
    x-group: Trajectories
  - name: artifacts
    x-group: Artifacts
  - name: telemetry
    x-group: Telemetry
  - name: supported-models
    x-group: Supported models
  - name: organizations
    x-group: Organizations
  - name: secrets
    x-group: Secrets
  - name: datasets
    x-group: Datasets
paths:
  /api/v1/datasets/{dataset_id}/trajectories:
    post:
      tags:
        - datasets
      summary: Add Dataset Trajectories
      description: >-
        Add a training/eval run's trajectories to a draft dataset. Poll the
        returned operation.
      operationId: addDatasetTrajectories
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            minLength: 1
            title: Dataset Id
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            minLength: 1
            maxLength: 256
            title: Idempotency-Key
          description: >-
            Optional. Without a key, repeated submissions are treated as
            separate actions. A blank or over-long key is rejected. Reuse this
            key when retrying a submission; the SDK generates one per call and
            reuses it across automatic retries.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddDatasetTrajectoriesRequest'
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DatasetOperation'
        '400':
          description: The request is malformed or cannot be processed.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Trajectory-Should-Retry:
              $ref: '#/components/headers/TrajectoryShouldRetry'
            Retry-After:
              $ref: '#/components/headers/RetryAfter'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorResponse'
        '404':
          description: >-
            The requested resource does not exist or is not visible to the
            caller.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Trajectory-Should-Retry:
              $ref: '#/components/headers/TrajectoryShouldRetry'
            Retry-After:
              $ref: '#/components/headers/RetryAfter'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResourceNotFoundErrorResponse'
        '409':
          description: >-
            The operation conflicts with the current state or an idempotent
            request.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Trajectory-Should-Retry:
              $ref: '#/components/headers/TrajectoryShouldRetry'
            Retry-After:
              $ref: '#/components/headers/RetryAfter'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConflictErrorResponse'
        default:
          $ref: '#/components/responses/ApiErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    AddDatasetTrajectoriesRequest:
      properties:
        training_run_ids:
          items:
            type: string
            maxLength: 64
            minLength: 1
          type: array
          title: Training Run Ids
          description: >-
            Succeeded or cancelled training runs whose completed train attempts
            join the train split.
        eval_run_ids:
          items:
            type: string
            maxLength: 64
            minLength: 1
          type: array
          title: Eval Run Ids
          description: Completed eval runs whose scored attempts join the heldout split.
        filter:
          oneOf:
            - $ref: '#/components/schemas/RewardThresholdFilter'
            - $ref: '#/components/schemas/NoErrorsFilter'
            - $ref: '#/components/schemas/BestPerTaskFilter'
          title: Filter
          discriminator:
            propertyName: type
            mapping:
              best_per_task: '#/components/schemas/BestPerTaskFilter'
              no_errors: '#/components/schemas/NoErrorsFilter'
              reward_threshold: '#/components/schemas/RewardThresholdFilter'
      additionalProperties: false
      type: object
      required:
        - filter
      title: AddDatasetTrajectoriesRequest
    DatasetOperation:
      properties:
        operation_id:
          type: string
          title: Operation Id
          description: Identifier to poll for the add's status.
        dataset_id:
          type: string
          title: Dataset Id
          description: The draft the trajectories are added to.
        status:
          type: string
          enum:
            - queued
            - running
            - succeeded
            - failed
          title: Status
          description: >-
            queued until a worker starts it; the draft can be finalized once it
            has finished.
        added_count:
          type: integer
          minimum: 0
          title: Added Count
          description: Trajectories added to the draft so far.
        skipped_count:
          type: integer
          minimum: 0
          title: Skipped Count
          description: Selected trajectories skipped because the draft already had them.
        error:
          anyOf:
            - $ref: '#/components/schemas/AsyncFailure'
            - type: 'null'
          description: Why the add failed, once failed; trajectories added before it stay.
        source_errors:
          items:
            $ref: '#/components/schemas/AsyncFailure'
          type: array
          title: Source Errors
          description: >-
            Any failed run IDs and their failure reasons; trajectories from the
            other runs stay.
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Time the add was accepted.
        completed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Completed At
          description: Time the add succeeded or failed.
      type: object
      required:
        - operation_id
        - dataset_id
        - status
        - added_count
        - skipped_count
        - error
        - source_errors
        - created_at
        - completed_at
      title: DatasetOperation
      description: Asynchronous add of trajectories to a draft dataset.
    InvalidRequestErrorResponse:
      properties:
        error:
          $ref: '#/components/schemas/InvalidRequestErrorBody'
      type: object
      required:
        - error
      title: InvalidRequestErrorResponse
    ResourceNotFoundErrorResponse:
      properties:
        error:
          $ref: '#/components/schemas/ResourceNotFoundErrorBody'
      type: object
      required:
        - error
      title: ResourceNotFoundErrorResponse
    ConflictErrorResponse:
      properties:
        error:
          $ref: '#/components/schemas/ConflictErrorBody'
      type: object
      required:
        - error
      title: ConflictErrorResponse
    RewardThresholdFilter:
      properties:
        type:
          type: string
          const: reward_threshold
          title: Type
          description: Keep attempts by reward.
        value:
          type: number
          title: Value
          description: Keep attempts whose reward is at least this finite value.
      additionalProperties: false
      type: object
      required:
        - type
        - value
      title: RewardThresholdFilter
    NoErrorsFilter:
      properties:
        type:
          type: string
          const: no_errors
          title: Type
          description: Keep every attempt that did not end in an error.
      additionalProperties: false
      type: object
      required:
        - type
      title: NoErrorsFilter
    BestPerTaskFilter:
      properties:
        type:
          type: string
          const: best_per_task
          title: Type
          description: >-
            Keep each task's highest-reward attempt in the run, however often it
            was visited.
      additionalProperties: false
      type: object
      required:
        - type
      title: BestPerTaskFilter
    AsyncFailure:
      properties:
        type:
          type: string
          title: Type
          description: Stable category used for exception mapping.
        code:
          type: string
          title: Code
          description: Stable programmatic reason for the asynchronous failure.
        message:
          type: string
          title: Message
          description: Human-readable explanation for this failure occurrence.
        context:
          additionalProperties: true
          type: object
          title: Context
          description: Machine-readable values specific to this failure code.
      type: object
      required:
        - type
        - code
        - message
      title: AsyncFailure
    InvalidRequestErrorBody:
      properties:
        type:
          type: string
          const: invalid_request_error
          title: Type
        code:
          type: string
          const: invalid_request
          title: Code
        message:
          type: string
          title: Message
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
        doc_url:
          type: string
          title: Doc Url
        context:
          $ref: '#/components/schemas/EmptyErrorContext'
      type: object
      required:
        - type
        - code
        - message
        - doc_url
        - context
      title: InvalidRequestErrorBody
    ResourceNotFoundErrorBody:
      properties:
        type:
          type: string
          const: invalid_request_error
          title: Type
        code:
          type: string
          const: resource_not_found
          title: Code
        message:
          type: string
          title: Message
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
        doc_url:
          type: string
          title: Doc Url
        context:
          $ref: '#/components/schemas/EmptyErrorContext'
      type: object
      required:
        - type
        - code
        - message
        - doc_url
        - context
      title: ResourceNotFoundErrorBody
    ConflictErrorBody:
      properties:
        type:
          type: string
          const: conflict_error
          title: Type
        code:
          type: string
          const: conflict
          title: Code
        message:
          type: string
          title: Message
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
        doc_url:
          type: string
          title: Doc Url
        context:
          $ref: '#/components/schemas/EmptyErrorContext'
      type: object
      required:
        - type
        - code
        - message
        - doc_url
        - context
      title: ConflictErrorBody
    ApiErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/ApiErrorBody'
      required:
        - error
      title: ApiErrorEnvelope
      type: object
    EmptyErrorContext:
      properties: {}
      additionalProperties: false
      type: object
      title: EmptyErrorContext
    ApiErrorBody:
      properties:
        type:
          $ref: '#/components/schemas/ErrorType'
        code:
          type: string
          title: Code
        message:
          type: string
          title: Message
        param:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Param
        doc_url:
          type: string
          title: Doc Url
        context:
          additionalProperties: true
          title: Context
          type: object
      required:
        - type
        - code
        - message
        - doc_url
        - context
      title: ApiErrorBody
      type: object
    ErrorType:
      enum:
        - invalid_request_error
        - authentication_error
        - permission_error
        - conflict_error
        - billing_error
        - rate_limit_error
        - dependency_error
        - api_error
      title: ErrorType
      type: string
  headers:
    RequestId:
      schema:
        type: string
    TrajectoryShouldRetry:
      schema:
        type: boolean
    RetryAfter:
      schema:
        type: string
  responses:
    ApiErrorResponse:
      description: >-
        Common API error. Possible codes: `authentication_required`,
        `permission_denied`, `validation_error`, `rate_limited`,
        `internal_error`, `service_unavailable`.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
        Trajectory-Should-Retry:
          $ref: '#/components/headers/TrajectoryShouldRetry'
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorEnvelope'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Organization API key

````

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