curl --request POST \
--url https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"samples": [
{
"model_input": {
"chunks": [
{
"encoded_text": {
"tokens": [
123,
456,
789
]
}
}
]
},
"loss_fn_inputs": {},
"routed_experts_key": "<string>"
}
],
"loss": {
"type": "LOSS_TYPE_GRPO",
"cross_entropy_params": {},
"grpo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2,
"beta": 0.1,
"agg_type": "GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON",
"ratio_type": "GRPO_LOSS_RATIO_TYPE_TOKEN"
},
"ppo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2
},
"cispo_params": {
"clip_low_threshold": 0,
"clip_high_threshold": 4
},
"dppo_params": {
"delta_low": 0.15,
"delta_high": 0.15
}
},
"return_loss_fn_outputs": true,
"forward_only": true
}
'import requests
url = "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward"
payload = {
"samples": [
{
"model_input": { "chunks": [{ "encoded_text": { "tokens": [123, 456, 789] } }] },
"loss_fn_inputs": {},
"routed_experts_key": "<string>"
}
],
"loss": {
"type": "LOSS_TYPE_GRPO",
"cross_entropy_params": {},
"grpo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2,
"beta": 0.1,
"agg_type": "GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON",
"ratio_type": "GRPO_LOSS_RATIO_TYPE_TOKEN"
},
"ppo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2
},
"cispo_params": {
"clip_low_threshold": 0,
"clip_high_threshold": 4
},
"dppo_params": {
"delta_low": 0.15,
"delta_high": 0.15
}
},
"return_loss_fn_outputs": True,
"forward_only": True
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
samples: [
{
model_input: {chunks: [{encoded_text: {tokens: [123, 456, 789]}}]},
loss_fn_inputs: {},
routed_experts_key: '<string>'
}
],
loss: {
type: 'LOSS_TYPE_GRPO',
cross_entropy_params: {},
grpo_params: {
clip_low_threshold: 0.8,
clip_high_threshold: 1.2,
beta: 0.1,
agg_type: 'GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON',
ratio_type: 'GRPO_LOSS_RATIO_TYPE_TOKEN'
},
ppo_params: {clip_low_threshold: 0.8, clip_high_threshold: 1.2},
cispo_params: {clip_low_threshold: 0, clip_high_threshold: 4},
dppo_params: {delta_low: 0.15, delta_high: 0.15}
},
return_loss_fn_outputs: true,
forward_only: true
})
};
fetch('https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'samples' => [
[
'model_input' => [
'chunks' => [
[
'encoded_text' => [
'tokens' => [
123,
456,
789
]
]
]
]
],
'loss_fn_inputs' => [
],
'routed_experts_key' => '<string>'
]
],
'loss' => [
'type' => 'LOSS_TYPE_GRPO',
'cross_entropy_params' => [
],
'grpo_params' => [
'clip_low_threshold' => 0.8,
'clip_high_threshold' => 1.2,
'beta' => 0.1,
'agg_type' => 'GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON',
'ratio_type' => 'GRPO_LOSS_RATIO_TYPE_TOKEN'
],
'ppo_params' => [
'clip_low_threshold' => 0.8,
'clip_high_threshold' => 1.2
],
'cispo_params' => [
'clip_low_threshold' => 0,
'clip_high_threshold' => 4
],
'dppo_params' => [
'delta_low' => 0.15,
'delta_high' => 0.15
]
],
'return_loss_fn_outputs' => true,
'forward_only' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward"
payload := strings.NewReader("{\n \"samples\": [\n {\n \"model_input\": {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n },\n \"loss_fn_inputs\": {},\n \"routed_experts_key\": \"<string>\"\n }\n ],\n \"loss\": {\n \"type\": \"LOSS_TYPE_GRPO\",\n \"cross_entropy_params\": {},\n \"grpo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2,\n \"beta\": 0.1,\n \"agg_type\": \"GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON\",\n \"ratio_type\": \"GRPO_LOSS_RATIO_TYPE_TOKEN\"\n },\n \"ppo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2\n },\n \"cispo_params\": {\n \"clip_low_threshold\": 0,\n \"clip_high_threshold\": 4\n },\n \"dppo_params\": {\n \"delta_low\": 0.15,\n \"delta_high\": 0.15\n }\n },\n \"return_loss_fn_outputs\": true,\n \"forward_only\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"samples\": [\n {\n \"model_input\": {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n },\n \"loss_fn_inputs\": {},\n \"routed_experts_key\": \"<string>\"\n }\n ],\n \"loss\": {\n \"type\": \"LOSS_TYPE_GRPO\",\n \"cross_entropy_params\": {},\n \"grpo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2,\n \"beta\": 0.1,\n \"agg_type\": \"GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON\",\n \"ratio_type\": \"GRPO_LOSS_RATIO_TYPE_TOKEN\"\n },\n \"ppo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2\n },\n \"cispo_params\": {\n \"clip_low_threshold\": 0,\n \"clip_high_threshold\": 4\n },\n \"dppo_params\": {\n \"delta_low\": 0.15,\n \"delta_high\": 0.15\n }\n },\n \"return_loss_fn_outputs\": true,\n \"forward_only\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"samples\": [\n {\n \"model_input\": {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n },\n \"loss_fn_inputs\": {},\n \"routed_experts_key\": \"<string>\"\n }\n ],\n \"loss\": {\n \"type\": \"LOSS_TYPE_GRPO\",\n \"cross_entropy_params\": {},\n \"grpo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2,\n \"beta\": 0.1,\n \"agg_type\": \"GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON\",\n \"ratio_type\": \"GRPO_LOSS_RATIO_TYPE_TOKEN\"\n },\n \"ppo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2\n },\n \"cispo_params\": {\n \"clip_low_threshold\": 0,\n \"clip_high_threshold\": 4\n },\n \"dppo_params\": {\n \"delta_low\": 0.15,\n \"delta_high\": 0.15\n }\n },\n \"return_loss_fn_outputs\": true,\n \"forward_only\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "TRAINING_OPERATION_STATUS_PENDING",
"output": {
"loss": 2.345,
"metrics": {
"loss/clip/high_fraction": 0.1,
"loss/kl_ref/mean": 0.05
},
"loss_fn_outputs": [
{
"tensors": {}
}
]
},
"error": {
"code": "TRAINING_OPERATION_ERROR_CODE_TIMEOUT",
"message": "Operation timed out"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Forward-backward pass
Submits a forward-backward pass operation that will asynchronously compute gradients via backpropagation.
curl --request POST \
--url https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"samples": [
{
"model_input": {
"chunks": [
{
"encoded_text": {
"tokens": [
123,
456,
789
]
}
}
]
},
"loss_fn_inputs": {},
"routed_experts_key": "<string>"
}
],
"loss": {
"type": "LOSS_TYPE_GRPO",
"cross_entropy_params": {},
"grpo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2,
"beta": 0.1,
"agg_type": "GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON",
"ratio_type": "GRPO_LOSS_RATIO_TYPE_TOKEN"
},
"ppo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2
},
"cispo_params": {
"clip_low_threshold": 0,
"clip_high_threshold": 4
},
"dppo_params": {
"delta_low": 0.15,
"delta_high": 0.15
}
},
"return_loss_fn_outputs": true,
"forward_only": true
}
'import requests
url = "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward"
payload = {
"samples": [
{
"model_input": { "chunks": [{ "encoded_text": { "tokens": [123, 456, 789] } }] },
"loss_fn_inputs": {},
"routed_experts_key": "<string>"
}
],
"loss": {
"type": "LOSS_TYPE_GRPO",
"cross_entropy_params": {},
"grpo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2,
"beta": 0.1,
"agg_type": "GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON",
"ratio_type": "GRPO_LOSS_RATIO_TYPE_TOKEN"
},
"ppo_params": {
"clip_low_threshold": 0.8,
"clip_high_threshold": 1.2
},
"cispo_params": {
"clip_low_threshold": 0,
"clip_high_threshold": 4
},
"dppo_params": {
"delta_low": 0.15,
"delta_high": 0.15
}
},
"return_loss_fn_outputs": True,
"forward_only": True
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
samples: [
{
model_input: {chunks: [{encoded_text: {tokens: [123, 456, 789]}}]},
loss_fn_inputs: {},
routed_experts_key: '<string>'
}
],
loss: {
type: 'LOSS_TYPE_GRPO',
cross_entropy_params: {},
grpo_params: {
clip_low_threshold: 0.8,
clip_high_threshold: 1.2,
beta: 0.1,
agg_type: 'GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON',
ratio_type: 'GRPO_LOSS_RATIO_TYPE_TOKEN'
},
ppo_params: {clip_low_threshold: 0.8, clip_high_threshold: 1.2},
cispo_params: {clip_low_threshold: 0, clip_high_threshold: 4},
dppo_params: {delta_low: 0.15, delta_high: 0.15}
},
return_loss_fn_outputs: true,
forward_only: true
})
};
fetch('https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'samples' => [
[
'model_input' => [
'chunks' => [
[
'encoded_text' => [
'tokens' => [
123,
456,
789
]
]
]
]
],
'loss_fn_inputs' => [
],
'routed_experts_key' => '<string>'
]
],
'loss' => [
'type' => 'LOSS_TYPE_GRPO',
'cross_entropy_params' => [
],
'grpo_params' => [
'clip_low_threshold' => 0.8,
'clip_high_threshold' => 1.2,
'beta' => 0.1,
'agg_type' => 'GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON',
'ratio_type' => 'GRPO_LOSS_RATIO_TYPE_TOKEN'
],
'ppo_params' => [
'clip_low_threshold' => 0.8,
'clip_high_threshold' => 1.2
],
'cispo_params' => [
'clip_low_threshold' => 0,
'clip_high_threshold' => 4
],
'dppo_params' => [
'delta_low' => 0.15,
'delta_high' => 0.15
]
],
'return_loss_fn_outputs' => true,
'forward_only' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward"
payload := strings.NewReader("{\n \"samples\": [\n {\n \"model_input\": {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n },\n \"loss_fn_inputs\": {},\n \"routed_experts_key\": \"<string>\"\n }\n ],\n \"loss\": {\n \"type\": \"LOSS_TYPE_GRPO\",\n \"cross_entropy_params\": {},\n \"grpo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2,\n \"beta\": 0.1,\n \"agg_type\": \"GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON\",\n \"ratio_type\": \"GRPO_LOSS_RATIO_TYPE_TOKEN\"\n },\n \"ppo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2\n },\n \"cispo_params\": {\n \"clip_low_threshold\": 0,\n \"clip_high_threshold\": 4\n },\n \"dppo_params\": {\n \"delta_low\": 0.15,\n \"delta_high\": 0.15\n }\n },\n \"return_loss_fn_outputs\": true,\n \"forward_only\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"samples\": [\n {\n \"model_input\": {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n },\n \"loss_fn_inputs\": {},\n \"routed_experts_key\": \"<string>\"\n }\n ],\n \"loss\": {\n \"type\": \"LOSS_TYPE_GRPO\",\n \"cross_entropy_params\": {},\n \"grpo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2,\n \"beta\": 0.1,\n \"agg_type\": \"GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON\",\n \"ratio_type\": \"GRPO_LOSS_RATIO_TYPE_TOKEN\"\n },\n \"ppo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2\n },\n \"cispo_params\": {\n \"clip_low_threshold\": 0,\n \"clip_high_threshold\": 4\n },\n \"dppo_params\": {\n \"delta_low\": 0.15,\n \"delta_high\": 0.15\n }\n },\n \"return_loss_fn_outputs\": true,\n \"forward_only\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/forward-backward")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"samples\": [\n {\n \"model_input\": {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n },\n \"loss_fn_inputs\": {},\n \"routed_experts_key\": \"<string>\"\n }\n ],\n \"loss\": {\n \"type\": \"LOSS_TYPE_GRPO\",\n \"cross_entropy_params\": {},\n \"grpo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2,\n \"beta\": 0.1,\n \"agg_type\": \"GRPO_LOSS_AGGREGATION_TYPE_FIXED_HORIZON\",\n \"ratio_type\": \"GRPO_LOSS_RATIO_TYPE_TOKEN\"\n },\n \"ppo_params\": {\n \"clip_low_threshold\": 0.8,\n \"clip_high_threshold\": 1.2\n },\n \"cispo_params\": {\n \"clip_low_threshold\": 0,\n \"clip_high_threshold\": 4\n },\n \"dppo_params\": {\n \"delta_low\": 0.15,\n \"delta_high\": 0.15\n }\n },\n \"return_loss_fn_outputs\": true,\n \"forward_only\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "TRAINING_OPERATION_STATUS_PENDING",
"output": {
"loss": 2.345,
"metrics": {
"loss/clip/high_fraction": 0.1,
"loss/kl_ref/mean": 0.05
},
"loss_fn_outputs": [
{
"tensors": {}
}
]
},
"error": {
"code": "TRAINING_OPERATION_ERROR_CODE_TIMEOUT",
"message": "Operation timed out"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Required key that makes retries return the original operation; use a new key for changed request bodies.
Path Parameters
Training session ID
Body
Batch of training samples to process
Show child attributes
Show child attributes
Loss function configuration
Show child attributes
Show child attributes
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.
true
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.
true
Response
Async forward-backward pass operation
Operation ID
"550e8400-e29b-41d4-a716-446655440000"
Operation status
TRAINING_OPERATION_STATUS_UNSPECIFIED, TRAINING_OPERATION_STATUS_PENDING, TRAINING_OPERATION_STATUS_RUNNING, TRAINING_OPERATION_STATUS_COMPLETED, TRAINING_OPERATION_STATUS_FAILED "TRAINING_OPERATION_STATUS_PENDING"
Result on success
Show child attributes
Show child attributes
Error details on failure
Show child attributes
Show child attributes
Was this page helpful?