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

> ## Agent Instructions
> Use https://docs.fastino.ai/llms.txt to discover and navigate pages. Use https://docs.fastino.ai/llms-full.txt when you need the complete documentation corpus. Use https://docs.fastino.ai/openapi.json as the source of truth for customer-facing routes. For GLiDE decision inference, call POST https://api.fastino.ai/v1/systemone with model fastino/GLiDE. Create managed config jobs with POST /v1/training/jobs using base_model. For custom training loops, native JSON clients use the public operations under /v1/training/jobs and /v1/training/usage. Existing Tinker clients use tinker==0.32.0 with TINKER_BASE_URL=https://api.fastino.ai/v1/training/compat/tinker and TINKER_CREDENTIAL_CMD. Compatibility child routes are private and absent from OpenAPI. Auto Train is private access and has no public route; direct interested users to sales@fastino.ai. Do not infer undocumented routes. Read API keys from FASTINO_API_KEY and never embed credentials in code, logs, or reports.

# Encolar una operación forward-backward

> Encola un pase forward-backward que acumula gradientes en un trabajo interactivo y luego consulta el future_id devuelto hasta un estado terminal.

`POST /v1/training/jobs/{job_id}/forward-backward`

Computes the loss of a batch of token-level datums and accumulates its
gradients. The next [optimizer step](/es/api-reference/training-jobs/interactive/optim-step)
applies them. The response is a future; read the loss and per-token log
probabilities from
[`GET /v1/training/jobs/{job_id}/futures/{future_id}`](/es/api-reference/training-jobs/interactive/get-future).

[`POST /v1/training/jobs/{job_id}/forward`](/es/api-reference/training-jobs/interactive/forward)
takes the same body and computes the loss without gradients.

## Request

<ParamField header="X-API-Key" type="string" required>
  Your Fastino API key.
</ParamField>

<ParamField path="job_id" type="string" required>
  Interactive job ID.
</ParamField>

<ParamField body="datums" type="object[]" required>
  One or more training examples. Tokenize them yourself with the base model's
  tokenizer.

  <Expandable title="properties">
    <ParamField body="model_input" type="object" required>
      `{"chunks": [{"type": "encoded_text", "tokens": [...]}]}`. The input token
      IDs, N tokens in total.
    </ParamField>

    <ParamField body="loss_fn_inputs" type="object" required>
      Per-position tensors, each `{"data": [...], "dtype": "int64" | "float32"}`
      with an optional `shape`. Every tensor has N values.

      * `target_tokens` (`int64`, required): the token expected at each position,
        usually the input shifted left by one.
      * `weights` (`float32`): per-position loss weight. Use `0` for prompt
        positions and `1` for completion positions.
      * `logprobs` and `advantages` (`float32`): required by every loss except
        `cross_entropy`. `logprobs` are the sampler's log probabilities of the
        targets.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="loss_fn" type="string" default="cross_entropy">
  `cross_entropy`, `importance_sampling`, `ppo`, `cispo`, or `dro`.
</ParamField>

<ParamField body="loss_fn_config" type="object">
  Loss settings. `ppo` and `cispo` take `clip_low_threshold` and
  `clip_high_threshold`; `dro` takes `beta`. Unknown keys are rejected.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.fastino.ai/v1/training/jobs/$TRAINING_JOB_ID/forward-backward" \
    -H "X-API-Key: $FASTINO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "loss_fn": "cross_entropy",
      "datums": [
        {
          "model_input": {"chunks": [{"type": "encoded_text", "tokens": [151644, 872, 198, 3838]}]},
          "loss_fn_inputs": {
            "target_tokens": {"data": [872, 198, 3838, 30], "dtype": "int64"},
            "weights": {"data": [0, 0, 1, 1], "dtype": "float32"}
          }
        }
      ]
    }'
  ```
</RequestExample>

## Response

<ResponseField name="future_id" type="string">
  The queued future.
</ResponseField>

<ResponseField name="job_id" type="string">
  The job.
</ResponseField>

<ResponseField name="type" type="string">
  `forward_backward`.
</ResponseField>

<ResponseExample>
  ```json Response theme={null}
  {
    "future_id": "FUTURE_ID",
    "job_id": "SESSION_ID:train:0",
    "type": "forward_backward"
  }
  ```

  ```json Completed future theme={null}
  {
    "future_id": "FUTURE_ID",
    "job_id": "SESSION_ID:train:0",
    "type": "forward_backward",
    "status": "completed",
    "result": {
      "loss_fn_output_type": "ArrayRecord",
      "loss_fn_outputs": [
        {"logprobs": {"data": [-3.1, -0.4, -1.2, -0.8], "dtype": "float32", "shape": [4]}}
      ],
      "metrics": {"loss:sum": 2.0}
    },
    "error": null
  }
  ```
</ResponseExample>

## Errors

| Status | Meaning |
| - | - |
| `400` | Unknown `loss_fn`, a non-integer `target_tokens` tensor, out-of-vocabulary token IDs, or the job was stopped. |
| `402` | The team is out of credits or has no valid payment setup. |
| `404` | The job doesn't exist or belongs to another team. |
| `422` | `datums` is empty or the body has an unknown field. |

Problems found while the batch runs, such as a missing loss input, mismatched
tensor lengths, an unknown `loss_fn_config` key, or a datum longer than the
model's limit, fail the future. Its `error.category` is `user`.


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