> ## 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. Start managed training (config job) with POST /v1/training/jobs using base_model. For interactive training, 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.

# Queue a forward-backward operation

> Queue a forward-backward pass that accumulates gradients on an interactive training job, then poll the returned future_id until it reaches a terminal status.

`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](https://docs.fastino.ai/api-reference/training-jobs/interactive/optim-step.md)
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}`](https://docs.fastino.ai/api-reference/training-jobs/interactive/get-future).

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

A GLiDE (`fastino/GLiDE`) job takes `decisions` instead of `datums`. See
[Train GLiDE](#train-glide) below.

## Request

**X-API-Key** `string` *required*

Your Fastino API key.

**job\_id** `string` *required*

Interactive job ID.

**datums** `object[]`

One or more training examples for a decoder job. Tokenize them yourself with
the base model's tokenizer. Send exactly one of `datums` and `decisions`.

**properties**

**model\_input** `object` *required*

`{"chunks": [{"type": "encoded_text", "tokens": [...]}]}`. The input token
IDs, N tokens in total.

**loss\_fn\_inputs** `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.

**decisions** `object[]`

GLiDE jobs only: decision rows instead of `datums`, at most `512`. On this
route every row needs `gold`, `soft_target`, or both.

**properties**

**state** `string | object | array` *required*

The situation, as [`POST /v1/systemone`](https://docs.fastino.ai/api-reference/inference/systemone)
takes it. Text only: image parts are refused.

**question** `object` *required*

One System One question (`noul`, `choice`, or `score`), as
`POST /v1/systemone` takes it.

**gold** `string`

The correct option: a `choice` criteria key, `true` or `false` for
`noul`, or a level index (`"0"`, `"1"`, ...) for `score`.

**soft\_target** `object`

Probability mass per option key, to distil. It's normalised over the
question's options; values are `0` or more, with a positive total.

**weight** `number` (default: 1)

The row's weight in the summed loss. Give each row `1/rows` to average a
step.

**loss\_fn** `string` (default: cross\_entropy)

`cross_entropy`, `importance_sampling`, `ppo`, `cispo`, or `dro` for a
decoder job. A GLiDE job uses `glide_decision`, its default.

**loss\_fn\_config** `object`

Loss settings. `ppo` and `cispo` take `clip_low_threshold` and
`clip_high_threshold`; `dro` takes `beta`; `glide_decision` takes
`ce_weight` (default `0.3`) and `kl_weight` (default `0.7`). Unknown keys are
rejected.

The numeric token arrays below are illustrative placeholders. Tokenize your
actual text with the tokenizer for the job's `base_model`.

```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"}
        }
      }
    ]
  }'
```

## Response

**future\_id** `string`

The queued future.

**job\_id** `string`

The job.

**type** `string`

`forward_backward`.

```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
}
```

## Train GLiDE

For a GLiDE job, `ce_weight` sets how much each row's loss counts `gold`, and
`kl_weight` how much it counts matching `soft_target`. A row with only `gold`
puts both weights on `gold`. The loss is summed over the rows, each scaled by
its `weight`. Each row can be at most `16,384` tokens.

```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": "glide_decision",
    "loss_fn_config": {"ce_weight": 0.3, "kl_weight": 0.7},
    "decisions": [
      {
        "state": "Customer: my card was charged twice for one order.",
        "question": {"type": "noul", "instructions": "Should this ticket go to billing?"},
        "gold": "true",
        "weight": 0.5
      },
      {
        "state": "Customer: how do I reset my password?",
        "question": {"type": "noul", "instructions": "Should this ticket go to billing?"},
        "soft_target": {"true": 0.1, "false": 0.9},
        "weight": 0.5
      }
    ]
  }'
```

The completed future's `result.loss_fn_outputs` holds each row's option
probabilities as `probs`, in the question's option order (`true`, `false` for
`noul`), and `result.metrics["loss:sum"]` holds the summed loss.

Rows that fail the schema, such as a `gold` that isn't one of the question's
options, a `soft_target` key that isn't an option or with no positive mass, or
an image state, return `422`. A row without `gold` or `soft_target`, a
`loss_fn` other than `glide_decision`, an unknown `loss_fn_config` key,
`decisions` on a decoder job, or `datums` on a GLiDE job return `400`.

## Errors

| Status | Meaning |
| - | - |
| `400` | Unknown `loss_fn`, a non-integer `target_tokens` tensor, out-of-vocabulary token IDs, the job was stopped, or a batch the model would refuse (see below). |
| `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` | The body sends both or neither of `datums` and `decisions`, either is empty, `decisions` has more than `512` rows, or the body has an unknown field. |
| `429` | The job already has `512` operations queued. Wait for its existing futures to finish before retrying. See [Interactive-job lifecycle](https://docs.fastino.ai/training.md#interactive-job-lifecycle). |

Before queuing the batch, the route also refuses with `400` what the model
would refuse: an unknown `loss_fn_config` key, an unknown `loss_fn_inputs` key,
a datum without `loss_fn_inputs.target_tokens` (or, for a reward loss, without
`logprobs` or `advantages`, or with `target_tokens` that isn't 1-D), and a datum
longer than the model's limit. Problems found only while the batch runs, such
as tensor lengths that don't match across a datum's inputs, fail the future.
Its `error.category` is `user`.


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