---
title: "Forward-backward pass"
method: POST
path: "/v1/rl/training-sessions/{session_id}/operations/forward-backward"
tags: ["RL"]
---

# Forward-backward pass

`POST /v1/rl/training-sessions/{session_id}/operations/forward-backward`

## Request

- Base URL: `https://api.together.ai`
- URL: `https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward`
- Auth: HTTP bearer

Submits a forward-backward pass operation that will asynchronously compute gradients via backpropagation.

## Path parameters

- `session_id` string, required: Training session ID

## Headers

- `Idempotency-Key` string, required: Required key that makes retries return the original operation; use a new key for changed request bodies.

## Request body

- RLForwardBackwardBody
  - `samples` RLTrainingSample[], required: Batch of training samples to process
    - `model_input` RLModelInput, required
      - `chunks` RLModelInputChunk[], required: Input chunks for the model
        - `encoded_text` RLEncodedTextChunk, required: Pre-tokenized text content for a model input chunk.
          - `tokens` union[], required: Pre-tokenized text input
            - union
              - …
    - `loss_fn_inputs` object, required: Per-token loss tensors keyed by name. Include `target_tokens` and the inputs required by the selected loss. Each tensor must declare `int64` or `float32`, be one-dimensional, and have the same length.
    - `routed_experts_key` string: Opaque key returned with a sampled sequence. Pass it unchanged with the corresponding training sample to reuse the same expert selections. The selections must cover the entire training sample or all but its final token. Training fails if the key is no longer available.
  - `loss` RLLossConfig, required
    - `type` 'LOSS_TYPE_UNSPECIFIED' | 'LOSS_TYPE_CROSS_ENTROPY' | 'LOSS_TYPE_GRPO' | 'LOSS_TYPE_IMPORTANCE_SAMPLING' | 'LOSS_TYPE_PPO' | 'LOSS_TYPE_CISPO' | 'LOSS_TYPE_DRO' | 'LOSS_TYPE_DPPO', required: Type of loss function used for RL training.
    - `cross_entropy_params` RLCrossEntropyLossParams: Cross-entropy loss parameters (currently empty).
    - `grpo_params` RLGRPOLossParams
      - `clip_low_threshold` number, float: Lower clip threshold for the importance-sampling ratio. The ratio is clamped to this bound; tighter clipping makes policy updates more conservative. Must be <= 1.
      - `clip_high_threshold` number, float: Upper clip threshold for the importance-sampling ratio. The ratio is clamped to this bound; tighter clipping makes policy updates more conservative. Must be >= 1.
      - `beta` number: KL penalty coefficient
      - `agg_type` 'GRPO_LOSS_AGGREGATION_TYPE_UNSPECIFIED' | 'GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON' | 'GRPO_LOSS_AGGREGATION_TYPE_TOKEN_MEAN' | 'GRPO_LOSS_AGGREGATION_TYPE_SEQUENCE_MEAN'
      - `ratio_type` 'GRPO_LOSS_RATIO_TYPE_TOKEN' | 'GRPO_LOSS_RATIO_TYPE_SEQUENCE': Controls whether GRPO loss uses token-level or sequence-level importance ratios.
    - `ppo_params` RLPPOLossParams
      - `clip_low_threshold` number, float: Lower absolute bound for the importance ratio in the clipped surrogate. Must be <= 1.
      - `clip_high_threshold` number, float: Upper absolute bound for the importance ratio in the clipped surrogate. Must be >= 1.
    - `cispo_params` RLCISPOLossParams
      - `clip_low_threshold` number, float: Lower bound for clipping the importance-sampling ratio.
      - `clip_high_threshold` number, float: Upper bound for clipping the importance-sampling ratio.
    - `dro_params` RLDROLossParams
      - `beta` number, float, required: Coefficient on the quadratic log-ratio penalty. Required; there is no default.
    - `dppo_params` RLDPPOLossParams: Parameters for DPPO loss. Both probability-change limits must be in [0, 1] and default to 0.15.
      - `delta_low` number, float: Probability-change limit for tokens with negative advantage. Measured in probability space, not log-probability space. Must be in [0, 1]. Defaults to 0.15.
      - `delta_high` number, float: Probability-change limit for tokens with positive advantage. Measured in probability space, not log-probability space. Must be in [0, 1]. Defaults to 0.15.
  - `return_loss_fn_outputs` boolean: Return the loss function's per-sample output tensors alongside the loss and metrics. Defaults to false. Enabling it increases the response size substantially for large batches and reduces step throughput, so leave it unset for ordinary training steps.
  - `forward_only` boolean: Run the forward pass only: report the loss and metrics, and the per-sample outputs when requested, without accumulating gradients. Defaults to false. Pair it with `return_loss_fn_outputs` to score a batch and read back its per-token log-probabilities.

## Response `200`

- RLForwardBackwardOperation: Async forward-backward pass operation
  - `id` string, required: Operation ID
  - `status` 'TRAINING_OPERATION_STATUS_UNSPECIFIED' | 'TRAINING_OPERATION_STATUS_PENDING' | 'TRAINING_OPERATION_STATUS_RUNNING' | 'TRAINING_OPERATION_STATUS_COMPLETED' | 'TRAINING_OPERATION_STATUS_FAILED', required
  - `output` RLForwardBackwardResult: Result of a scored forward or forward-backward operation
    - `loss` number, required: Loss value
    - `metrics` object: Loss-specific metrics (e.g., KL divergence, clip fraction for GRPO)
    - `loss_fn_outputs` RLLossFnOutput[]: Per-sample loss function outputs, in request order. Empty unless the request set `return_loss_fn_outputs`.
      - `tensors` object, required: Output tensors keyed by name. Built-in losses return `logprobs`: the model's float32 per-token log-probabilities under the current policy, one value per token of the sample's input. Positions excluded from the loss, such as zero-weight positions, are masked to zero rather than true log-probabilities.
  - `error` RLTrainingOperationError: Error details for a failed training operation
    - `code` 'TRAINING_OPERATION_ERROR_CODE_UNSPECIFIED' | 'TRAINING_OPERATION_ERROR_CODE_RESOURCE_EXHAUSTED' | 'TRAINING_OPERATION_ERROR_CODE_TIMEOUT' | 'TRAINING_OPERATION_ERROR_CODE_INTERNAL_ERROR' | 'TRAINING_OPERATION_ERROR_CODE_SESSION_NOT_ACTIVE' | 'TRAINING_OPERATION_ERROR_CODE_INVALID_INPUT' | 'TRAINING_OPERATION_ERROR_CODE_NON_FINITE_LOSS': Application error code for a failed training operation
    - `message` string: Human-readable error message

## Other responses

- `default`: An unexpected error response.

## Changes

- **2026-10-22** `bb5257b3173a`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/together/apis/together-apis/changes/v1/rl/training-sessions/:session_id/operations/forward-backward/post.md)

---

[API](https://skmtc.dev/together/apis/together-apis.md) - [All operations](https://skmtc.dev/together/apis/together-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/together/apis/together-apis/revisions/93438ddac711?raw)
