> ## Documentation Index
> Fetch the complete documentation index at: https://staging.docs.trywhitney.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Submit an ordered training primitive.

> `seq_id` must equal the run's `next_seq_id`; retries reuse the exact
idempotency key and canonical request hash. Token IDs and tensor values
use the typed JSON payload for the selected operation. Callers may use
run-scoped `sample` as their first sampler action:
Whitney atomically creates its durable sampler and synchronizes the
current weights inside that one operation. Explicit sampler-save
remains available when a caller wants its cold start separately.




## OpenAPI

````yaml /openapi.yaml post /v1/training/runs/{run_id}/operations
openapi: 3.1.0
info:
  title: Whitney Training API
  version: 0.3.0
  description: >
    Public HTTP API for caller-owned model training on Whitney.


    Authenticate with a Whitney API key (`whitney_test_…` or `whitney_live_…`).

    Create a session and run, submit ordered training and sampling primitives,

    poll durable operations, and retrieve checkpoints, artifacts, usage, and
    cost.


    Every public request uses typed JSON. Token IDs and dense tensor values are

    ordinary JSON arrays validated against strict, provider-neutral schemas.
servers:
  - url: http://localhost:3001
    description: Local API
  - url: https://api.staging.trywhitney.com
    description: Staging API
  - url: https://api.trywhitney.com
    description: Production API
security:
  - WhitneyApiKey: []
tags:
  - name: unified-training
    description: Whitney-owned session, primitive, and operations API.
paths:
  /v1/training/runs/{run_id}/operations:
    parameters:
      - $ref: '#/components/parameters/RunId'
    post:
      tags:
        - unified-training
      summary: Submit an ordered training primitive.
      description: |
        `seq_id` must equal the run's `next_seq_id`; retries reuse the exact
        idempotency key and canonical request hash. Token IDs and tensor values
        use the typed JSON payload for the selected operation. Callers may use
        run-scoped `sample` as their first sampler action:
        Whitney atomically creates its durable sampler and synchronizes the
        current weights inside that one operation. Explicit sampler-save
        remains available when a caller wants its cold start separately.
      operationId: submitTrainingRunOperation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RunOperationRequest'
      responses:
        '202':
          description: >-
            Durable operation handle; poll this object rather than holding the
            request open.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Operation'
        default:
          $ref: '#/components/responses/ApiError'
components:
  parameters:
    RunId:
      name: run_id
      in: path
      required: true
      schema:
        $ref: '#/components/schemas/RunId'
  schemas:
    RunOperationRequest:
      type: object
      additionalProperties: false
      required:
        - seq_id
        - idempotency_key
        - request_hash
        - kind
      properties:
        seq_id:
          type: integer
          minimum: 1
          maximum: 2147483647
        idempotency_key:
          type: string
          minLength: 1
          maxLength: 200
        request_hash:
          type: string
          pattern: ^[0-9a-f]{64}$
          description: >-
            SHA-256 of the canonical JSON operation envelope excluding
            request_hash.
        kind:
          type: string
          enum:
            - forward
            - forward_backward
            - sample
            - optim_step
            - save_state
            - load_state
            - save_weights_for_sampler
            - export_lora
        payload:
          type: object
          additionalProperties: true
      allOf:
        - if:
            properties:
              kind:
                enum:
                  - forward
                  - forward_backward
            required:
              - kind
          then:
            required:
              - payload
            properties:
              payload:
                $ref: '#/components/schemas/ForwardPayload'
        - if:
            properties:
              kind:
                const: sample
            required:
              - kind
          then:
            required:
              - payload
            properties:
              payload:
                $ref: '#/components/schemas/SamplePayload'
        - if:
            properties:
              kind:
                const: optim_step
            required:
              - kind
          then:
            properties:
              payload:
                type: object
                additionalProperties: false
                required:
                  - optimizer
                properties:
                  optimizer:
                    $ref: '#/components/schemas/AdamWOptimizer'
        - if:
            properties:
              kind:
                const: load_state
            required:
              - kind
          then:
            properties:
              payload:
                type: object
                additionalProperties: false
                required:
                  - checkpoint_id
                properties:
                  checkpoint_id:
                    $ref: '#/components/schemas/CheckpointId'
                  with_optimizer:
                    type: boolean
        - if:
            properties:
              kind:
                enum:
                  - save_state
                  - save_weights_for_sampler
                  - export_lora
            required:
              - kind
          then:
            properties:
              payload:
                type: object
                additionalProperties: false
    Operation:
      type: object
      additionalProperties: false
      required:
        - id
        - session_id
        - run_id
        - seq_id
        - kind
        - status
        - result
        - error_code
        - progress
        - progress_updated_at
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/OperationId'
        session_id:
          $ref: '#/components/schemas/SessionId'
        run_id:
          $ref: '#/components/schemas/RunId'
        seq_id:
          type: integer
          minimum: 1
        kind:
          type: string
          enum:
            - forward
            - forward_backward
            - optim_step
            - save_state
            - load_state
            - save_weights_for_sampler
            - export_lora
            - sample
            - logprobs
            - finish
            - cancel
        status:
          type: string
          enum:
            - parked
            - pending
            - executing
            - succeeded
            - failed
            - cancelled
        result:
          type:
            - object
            - 'null'
          additionalProperties: true
        error_code:
          type:
            - string
            - 'null'
        progress:
          type:
            - object
            - 'null'
          additionalProperties: true
        progress_updated_at:
          oneOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
    RunId:
      type: string
      pattern: ^wtr_[0-9a-f]{32}$
    OperationId:
      type: string
      pattern: ^wto_[0-9a-f]{32}$
    SessionId:
      type: string
      pattern: ^wts_[0-9a-f]{32}$
    Timestamp:
      type: string
      format: date-time
    ErrorResponse:
      type: object
      additionalProperties: false
      required:
        - error
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
        request_id:
          type: string
        funding_source:
          type: string
          enum:
            - platform
            - byok
  responses:
    ApiError:
      description: Whitney API error envelope.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    WhitneyApiKey:
      type: http
      scheme: bearer
      bearerFormat: whitney_test_|whitney_live_
      description: Whitney-issued API key. No organization-selection header is accepted.

````