curl --request POST \
--url https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"model_inputs": [
{
"chunks": [
{
"encoded_text": {
"tokens": [
123,
456,
789
]
}
}
]
}
],
"sampling_params": {
"max_tokens": 512,
"temperature": 1,
"top_p": 1,
"top_k": -1,
"stop": [
"\n",
"END"
],
"seed": "42"
},
"num_samples": 1,
"prompt_logprobs": false,
"topk_prompt_logprobs": 0,
"return_routed_experts": false
}
'import requests
url = "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample"
payload = {
"model_inputs": [{ "chunks": [{ "encoded_text": { "tokens": [123, 456, 789] } }] }],
"sampling_params": {
"max_tokens": 512,
"temperature": 1,
"top_p": 1,
"top_k": -1,
"stop": ["
", "END"],
"seed": "42"
},
"num_samples": 1,
"prompt_logprobs": False,
"topk_prompt_logprobs": 0,
"return_routed_experts": False
}
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({
model_inputs: [{chunks: [{encoded_text: {tokens: [123, 456, 789]}}]}],
sampling_params: {
max_tokens: 512,
temperature: 1,
top_p: 1,
top_k: -1,
stop: ['\n', 'END'],
seed: '42'
},
num_samples: 1,
prompt_logprobs: false,
topk_prompt_logprobs: 0,
return_routed_experts: false
})
};
fetch('https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample', 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/sample",
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([
'model_inputs' => [
[
'chunks' => [
[
'encoded_text' => [
'tokens' => [
123,
456,
789
]
]
]
]
]
],
'sampling_params' => [
'max_tokens' => 512,
'temperature' => 1,
'top_p' => 1,
'top_k' => -1,
'stop' => [
'
',
'END'
],
'seed' => '42'
],
'num_samples' => 1,
'prompt_logprobs' => false,
'topk_prompt_logprobs' => 0,
'return_routed_experts' => false
]),
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/sample"
payload := strings.NewReader("{\n \"model_inputs\": [\n {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n }\n ],\n \"sampling_params\": {\n \"max_tokens\": 512,\n \"temperature\": 1,\n \"top_p\": 1,\n \"top_k\": -1,\n \"stop\": [\n \"\\n\",\n \"END\"\n ],\n \"seed\": \"42\"\n },\n \"num_samples\": 1,\n \"prompt_logprobs\": false,\n \"topk_prompt_logprobs\": 0,\n \"return_routed_experts\": false\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/sample")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model_inputs\": [\n {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n }\n ],\n \"sampling_params\": {\n \"max_tokens\": 512,\n \"temperature\": 1,\n \"top_p\": 1,\n \"top_k\": -1,\n \"stop\": [\n \"\\n\",\n \"END\"\n ],\n \"seed\": \"42\"\n },\n \"num_samples\": 1,\n \"prompt_logprobs\": false,\n \"topk_prompt_logprobs\": 0,\n \"return_routed_experts\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample")
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 \"model_inputs\": [\n {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n }\n ],\n \"sampling_params\": {\n \"max_tokens\": 512,\n \"temperature\": 1,\n \"top_p\": 1,\n \"top_k\": -1,\n \"stop\": [\n \"\\n\",\n \"END\"\n ],\n \"seed\": \"42\"\n },\n \"num_samples\": 1,\n \"prompt_logprobs\": false,\n \"topk_prompt_logprobs\": 0,\n \"return_routed_experts\": false\n}"
response = http.request(request)
puts response.read_body{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "TRAINING_OPERATION_STATUS_PENDING",
"output": {
"results": [
{
"sequences": [
{
"tokens": [
"123",
"456",
"789"
],
"stop_reason": "STOP_REASON_LENGTH",
"prompt_cache_hit_tokens": 1024,
"logprobs": [
-0.5,
-1.2,
-0.3
],
"routed_experts_key": "<string>"
}
],
"policy_segments": [
{
"version": 5,
"start_token": 0
}
],
"prompt_logprobs": [
0,
-0.5,
-1.2
],
"topk_prompt_logprobs": [
{
"token_ids": [
123,
456
],
"logprobs": [
-0.5,
-2.1
]
}
]
}
]
},
"error": {
"code": "TRAINING_OPERATION_ERROR_CODE_TIMEOUT",
"message": "Operation timed out"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Sample
Submits a sample operation that will asynchronously generate text completions with logprobs.
curl --request POST \
--url https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"model_inputs": [
{
"chunks": [
{
"encoded_text": {
"tokens": [
123,
456,
789
]
}
}
]
}
],
"sampling_params": {
"max_tokens": 512,
"temperature": 1,
"top_p": 1,
"top_k": -1,
"stop": [
"\n",
"END"
],
"seed": "42"
},
"num_samples": 1,
"prompt_logprobs": false,
"topk_prompt_logprobs": 0,
"return_routed_experts": false
}
'import requests
url = "https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample"
payload = {
"model_inputs": [{ "chunks": [{ "encoded_text": { "tokens": [123, 456, 789] } }] }],
"sampling_params": {
"max_tokens": 512,
"temperature": 1,
"top_p": 1,
"top_k": -1,
"stop": ["
", "END"],
"seed": "42"
},
"num_samples": 1,
"prompt_logprobs": False,
"topk_prompt_logprobs": 0,
"return_routed_experts": False
}
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({
model_inputs: [{chunks: [{encoded_text: {tokens: [123, 456, 789]}}]}],
sampling_params: {
max_tokens: 512,
temperature: 1,
top_p: 1,
top_k: -1,
stop: ['\n', 'END'],
seed: '42'
},
num_samples: 1,
prompt_logprobs: false,
topk_prompt_logprobs: 0,
return_routed_experts: false
})
};
fetch('https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample', 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/sample",
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([
'model_inputs' => [
[
'chunks' => [
[
'encoded_text' => [
'tokens' => [
123,
456,
789
]
]
]
]
]
],
'sampling_params' => [
'max_tokens' => 512,
'temperature' => 1,
'top_p' => 1,
'top_k' => -1,
'stop' => [
'
',
'END'
],
'seed' => '42'
],
'num_samples' => 1,
'prompt_logprobs' => false,
'topk_prompt_logprobs' => 0,
'return_routed_experts' => false
]),
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/sample"
payload := strings.NewReader("{\n \"model_inputs\": [\n {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n }\n ],\n \"sampling_params\": {\n \"max_tokens\": 512,\n \"temperature\": 1,\n \"top_p\": 1,\n \"top_k\": -1,\n \"stop\": [\n \"\\n\",\n \"END\"\n ],\n \"seed\": \"42\"\n },\n \"num_samples\": 1,\n \"prompt_logprobs\": false,\n \"topk_prompt_logprobs\": 0,\n \"return_routed_experts\": false\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/sample")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model_inputs\": [\n {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n }\n ],\n \"sampling_params\": {\n \"max_tokens\": 512,\n \"temperature\": 1,\n \"top_p\": 1,\n \"top_k\": -1,\n \"stop\": [\n \"\\n\",\n \"END\"\n ],\n \"seed\": \"42\"\n },\n \"num_samples\": 1,\n \"prompt_logprobs\": false,\n \"topk_prompt_logprobs\": 0,\n \"return_routed_experts\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.ai/v1/rl/training-sessions/{session_id}/operations/sample")
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 \"model_inputs\": [\n {\n \"chunks\": [\n {\n \"encoded_text\": {\n \"tokens\": [\n 123,\n 456,\n 789\n ]\n }\n }\n ]\n }\n ],\n \"sampling_params\": {\n \"max_tokens\": 512,\n \"temperature\": 1,\n \"top_p\": 1,\n \"top_k\": -1,\n \"stop\": [\n \"\\n\",\n \"END\"\n ],\n \"seed\": \"42\"\n },\n \"num_samples\": 1,\n \"prompt_logprobs\": false,\n \"topk_prompt_logprobs\": 0,\n \"return_routed_experts\": false\n}"
response = http.request(request)
puts response.read_body{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "TRAINING_OPERATION_STATUS_PENDING",
"output": {
"results": [
{
"sequences": [
{
"tokens": [
"123",
"456",
"789"
],
"stop_reason": "STOP_REASON_LENGTH",
"prompt_cache_hit_tokens": 1024,
"logprobs": [
-0.5,
-1.2,
-0.3
],
"routed_experts_key": "<string>"
}
],
"policy_segments": [
{
"version": 5,
"start_token": 0
}
],
"prompt_logprobs": [
0,
-0.5,
-1.2
],
"topk_prompt_logprobs": [
{
"token_ids": [
123,
456
],
"logprobs": [
-0.5,
-2.1
]
}
]
}
]
},
"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
Model inputs to sample from
Show child attributes
Show child attributes
Optional sampling parameters
Show child attributes
Show child attributes
Number of completions to generate per prompt
1
When true, also compute teacher-forced log-probabilities for the model input tokens and return them in SampleResult.prompt_logprobs.
false
Number of most likely alternative tokens to return per model input token in SampleResult.topk_prompt_logprobs. 0 disables top-k prompt log-probabilities. Maximum 20.
0 <= x <= 200
When true, enable reuse of the expert selections from sampled sequences during training. Only supported for mixture-of-experts models; ignored for other models.
false
Response
Async sample 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?