Create a sampler
Creates a standalone Loops sampler not linked to a run.
curl --request POST \
--url https://api.baseten.co/v1/loops/samplers \
--header "Authorization: Bearer $BASETEN_API_KEY" \
--data '{
"session_id": null,
"base_model": null,
"run_id": null,
"max_seq_length": null,
"model_path": "bt://loops:k4q95w5/sampler_weights/step-100",
"reuse_from_session_id": null
}'import requests
import os
API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
url = "https://api.baseten.co/v1/loops/samplers"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.request(
"POST",
url,
headers=headers,
json={'session_id': None, 'base_model': None, 'run_id': None, 'max_seq_length': None, 'model_path': 'bt://loops:k4q95w5/sampler_weights/step-100', 'reuse_from_session_id': None}
)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
session_id: '<string>',
base_model: '<string>',
run_id: '<string>',
max_seq_length: 123,
model_path: 'bt://loops:k4q95w5/sampler_weights/step-100',
reuse_from_session_id: '<string>'
})
};
fetch('https://api.baseten.co/v1/loops/samplers', 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.baseten.co/v1/loops/samplers",
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([
'session_id' => '<string>',
'base_model' => '<string>',
'run_id' => '<string>',
'max_seq_length' => 123,
'model_path' => 'bt://loops:k4q95w5/sampler_weights/step-100',
'reuse_from_session_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.baseten.co/v1/loops/samplers"
payload := strings.NewReader("{\n \"session_id\": \"<string>\",\n \"base_model\": \"<string>\",\n \"run_id\": \"<string>\",\n \"max_seq_length\": 123,\n \"model_path\": \"bt://loops:k4q95w5/sampler_weights/step-100\",\n \"reuse_from_session_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.baseten.co/v1/loops/samplers")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"session_id\": \"<string>\",\n \"base_model\": \"<string>\",\n \"run_id\": \"<string>\",\n \"max_seq_length\": 123,\n \"model_path\": \"bt://loops:k4q95w5/sampler_weights/step-100\",\n \"reuse_from_session_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.baseten.co/v1/loops/samplers")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"session_id\": \"<string>\",\n \"base_model\": \"<string>\",\n \"run_id\": \"<string>\",\n \"max_seq_length\": 123,\n \"model_path\": \"bt://loops:k4q95w5/sampler_weights/step-100\",\n \"reuse_from_session_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"sampler": {
"id": "<string>",
"base_url": "<string>",
"base_model": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"model_id": "<string>",
"deployment_id": "<string>",
"status": {}
}
}Authorizations
Send Authorization: Bearer <api_key>. The legacy Authorization: Api-Key <api_key> scheme is also accepted.
Body
ID of the Loops session this sampler belongs to.
Base model ID for a standalone sampler (for example, a baseline).
ID of an existing run to attach this sampler to. When set, the sampler is paired to the run and weight-syncs from its trainer, and base_model is inherited from the run. Omit to create a standalone sampler.
Maximum prompt length (in tokens) the sampler must handle. Set this to the longest prompt you plan to send.
bt:// URI of an existing sampler checkpoint to serve. Form: bt://loops:<run_id>/sampler_weights/<checkpoint_name>.
"bt://loops:k4q95w5/sampler_weights/step-100"
Optional Loops session ID to reuse infrastructure from. Best-effort.
Response
Show child attributes
Show child attributes
Was this page helpful?
curl --request POST \
--url https://api.baseten.co/v1/loops/samplers \
--header "Authorization: Bearer $BASETEN_API_KEY" \
--data '{
"session_id": null,
"base_model": null,
"run_id": null,
"max_seq_length": null,
"model_path": "bt://loops:k4q95w5/sampler_weights/step-100",
"reuse_from_session_id": null
}'import requests
import os
API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
url = "https://api.baseten.co/v1/loops/samplers"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.request(
"POST",
url,
headers=headers,
json={'session_id': None, 'base_model': None, 'run_id': None, 'max_seq_length': None, 'model_path': 'bt://loops:k4q95w5/sampler_weights/step-100', 'reuse_from_session_id': None}
)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
session_id: '<string>',
base_model: '<string>',
run_id: '<string>',
max_seq_length: 123,
model_path: 'bt://loops:k4q95w5/sampler_weights/step-100',
reuse_from_session_id: '<string>'
})
};
fetch('https://api.baseten.co/v1/loops/samplers', 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.baseten.co/v1/loops/samplers",
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([
'session_id' => '<string>',
'base_model' => '<string>',
'run_id' => '<string>',
'max_seq_length' => 123,
'model_path' => 'bt://loops:k4q95w5/sampler_weights/step-100',
'reuse_from_session_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.baseten.co/v1/loops/samplers"
payload := strings.NewReader("{\n \"session_id\": \"<string>\",\n \"base_model\": \"<string>\",\n \"run_id\": \"<string>\",\n \"max_seq_length\": 123,\n \"model_path\": \"bt://loops:k4q95w5/sampler_weights/step-100\",\n \"reuse_from_session_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.baseten.co/v1/loops/samplers")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"session_id\": \"<string>\",\n \"base_model\": \"<string>\",\n \"run_id\": \"<string>\",\n \"max_seq_length\": 123,\n \"model_path\": \"bt://loops:k4q95w5/sampler_weights/step-100\",\n \"reuse_from_session_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.baseten.co/v1/loops/samplers")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"session_id\": \"<string>\",\n \"base_model\": \"<string>\",\n \"run_id\": \"<string>\",\n \"max_seq_length\": 123,\n \"model_path\": \"bt://loops:k4q95w5/sampler_weights/step-100\",\n \"reuse_from_session_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"sampler": {
"id": "<string>",
"base_url": "<string>",
"base_model": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"model_id": "<string>",
"deployment_id": "<string>",
"status": {}
}
}