Track Request
curl --request POST \
--url https://api.promptlayer.com/rest/track-request \
--header 'Content-Type: application/json' \
--data '
{
"function_name": "<string>",
"kwargs": {},
"request_response": {},
"request_start_time": 123,
"request_end_time": 123,
"tags": [
{}
],
"prompt_id": "<string>",
"prompt_input_variables": {},
"prompt_version": 123,
"api_key": "<string>"
}
'import requests
url = "https://api.promptlayer.com/rest/track-request"
payload = {
"function_name": "<string>",
"kwargs": {},
"request_response": {},
"request_start_time": 123,
"request_end_time": 123,
"tags": [{}],
"prompt_id": "<string>",
"prompt_input_variables": {},
"prompt_version": 123,
"api_key": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
function_name: '<string>',
kwargs: {},
request_response: {},
request_start_time: 123,
request_end_time: 123,
tags: [{}],
prompt_id: '<string>',
prompt_input_variables: {},
prompt_version: 123,
api_key: '<string>'
})
};
fetch('https://api.promptlayer.com/rest/track-request', 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.promptlayer.com/rest/track-request",
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([
'function_name' => '<string>',
'kwargs' => [
],
'request_response' => [
],
'request_start_time' => 123,
'request_end_time' => 123,
'tags' => [
[
]
],
'prompt_id' => '<string>',
'prompt_input_variables' => [
],
'prompt_version' => 123,
'api_key' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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.promptlayer.com/rest/track-request"
payload := strings.NewReader("{\n \"function_name\": \"<string>\",\n \"kwargs\": {},\n \"request_response\": {},\n \"request_start_time\": 123,\n \"request_end_time\": 123,\n \"tags\": [\n {}\n ],\n \"prompt_id\": \"<string>\",\n \"prompt_input_variables\": {},\n \"prompt_version\": 123,\n \"api_key\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.promptlayer.com/rest/track-request")
.header("Content-Type", "application/json")
.body("{\n \"function_name\": \"<string>\",\n \"kwargs\": {},\n \"request_response\": {},\n \"request_start_time\": 123,\n \"request_end_time\": 123,\n \"tags\": [\n {}\n ],\n \"prompt_id\": \"<string>\",\n \"prompt_input_variables\": {},\n \"prompt_version\": 123,\n \"api_key\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.promptlayer.com/rest/track-request")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"function_name\": \"<string>\",\n \"kwargs\": {},\n \"request_response\": {},\n \"request_start_time\": 123,\n \"request_end_time\": 123,\n \"tags\": [\n {}\n ],\n \"prompt_id\": \"<string>\",\n \"prompt_input_variables\": {},\n \"prompt_version\": 123,\n \"api_key\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyReference
Track Request
POST
/
rest
/
track-request
Track Request
curl --request POST \
--url https://api.promptlayer.com/rest/track-request \
--header 'Content-Type: application/json' \
--data '
{
"function_name": "<string>",
"kwargs": {},
"request_response": {},
"request_start_time": 123,
"request_end_time": 123,
"tags": [
{}
],
"prompt_id": "<string>",
"prompt_input_variables": {},
"prompt_version": 123,
"api_key": "<string>"
}
'import requests
url = "https://api.promptlayer.com/rest/track-request"
payload = {
"function_name": "<string>",
"kwargs": {},
"request_response": {},
"request_start_time": 123,
"request_end_time": 123,
"tags": [{}],
"prompt_id": "<string>",
"prompt_input_variables": {},
"prompt_version": 123,
"api_key": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
function_name: '<string>',
kwargs: {},
request_response: {},
request_start_time: 123,
request_end_time: 123,
tags: [{}],
prompt_id: '<string>',
prompt_input_variables: {},
prompt_version: 123,
api_key: '<string>'
})
};
fetch('https://api.promptlayer.com/rest/track-request', 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.promptlayer.com/rest/track-request",
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([
'function_name' => '<string>',
'kwargs' => [
],
'request_response' => [
],
'request_start_time' => 123,
'request_end_time' => 123,
'tags' => [
[
]
],
'prompt_id' => '<string>',
'prompt_input_variables' => [
],
'prompt_version' => 123,
'api_key' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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.promptlayer.com/rest/track-request"
payload := strings.NewReader("{\n \"function_name\": \"<string>\",\n \"kwargs\": {},\n \"request_response\": {},\n \"request_start_time\": 123,\n \"request_end_time\": 123,\n \"tags\": [\n {}\n ],\n \"prompt_id\": \"<string>\",\n \"prompt_input_variables\": {},\n \"prompt_version\": 123,\n \"api_key\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.promptlayer.com/rest/track-request")
.header("Content-Type", "application/json")
.body("{\n \"function_name\": \"<string>\",\n \"kwargs\": {},\n \"request_response\": {},\n \"request_start_time\": 123,\n \"request_end_time\": 123,\n \"tags\": [\n {}\n ],\n \"prompt_id\": \"<string>\",\n \"prompt_input_variables\": {},\n \"prompt_version\": 123,\n \"api_key\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.promptlayer.com/rest/track-request")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"function_name\": \"<string>\",\n \"kwargs\": {},\n \"request_response\": {},\n \"request_start_time\": 123,\n \"request_end_time\": 123,\n \"tags\": [\n {}\n ],\n \"prompt_id\": \"<string>\",\n \"prompt_input_variables\": {},\n \"prompt_version\": 123,\n \"api_key\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyTrack request allows you to send your LLM request to our platform. On success, this request will return a
request_id which is necessary for track-score
Example Code
import requests
# URL and headers
url = "http://api.promptlayer.com/track-request"
headers = {
"Content-Type": "application/json",
}
# Data payload
data_payload = {
"function_name": "openai.ChatCompletion.create",
"kwargs": {
"messages": [
{
"content": "You are a helpful AI assistant.",
"role": "system"
},
{
"content": "What's the weather like in Boston?",
"role": "user"
}
],
"model": "gpt-3.5-turbo-16k",
"function_call": "auto",
"functions": [
{
"description": "Get the current weather in a given location",
"name": "get_current_weather",
"parameters": {
"properties": {
"location": {
"description": "The city and state, e.g. San Francisco, CA",
"type": "string"
},
"unit": {
"enum": [
"celsius",
"fahrenheit"
],
"type": "string"
}
},
"required": [
"location"
],
"type": "object"
}
}
]
},
"request_response": {
"choices": [
{
"index": 0,
"message": {
"content": "",
"function_call": {
"arguments": "{\n\"location\": \"Boston, MA\"\n}",
"name": "get_current_weather"
},
"role": "assistant"
},
"finish_reason": "function_call"
}
],
"usage": {
"prompt_tokens": 778,
"completion_tokens": 28,
"total_tokens": 806
}
},
"tags": [
"docs"
],
"request_start_time": 1693505089.21,
"request_end_time": 1693505093.572,
"api_key": "pl_<YOUR_API_KEY>"
}
# Making the request
response = requests.post(url, headers=headers, json=data_payload)
print(response.json())
import requests
# URL and headers
url = "http://api.promptlayer.com/track-request"
headers = {
"Content-Type": "application/json",
}
# Data payload
data_payload = {
"function_name": "openai.Completion.create",
"kwargs": {"engine": "text-ada-001", "prompt": "My name is"},
"tags": ["hello", "world"],
"request_response": {
"id": "cmpl-6TEeJCRVlqQSQqhD8CYKd1HdCcFxM",
"object": "text_completion",
"created": 1672425843,
"model": "text-ada-001",
"choices": [
{
"text": " PromptLayer\"\n\nI'm a great prompt engineering tool.",
"index": 0,
"logprobs": None,
"finish_reason": "stop"
}
]
},
"request_start_time": 1673987077.463504,
"request_end_time": 1673987077.463504,
"api_key": "pl_<YOUR_API_KEY>",
}
# Making the request
response = requests.post("https://api.promptlayer.com/rest/track-request", json=data_payload)
print(response.json())
Request Parameters
string
The name of the function. For example, if you are using OpenAI it should be either
openai.Completion.create or openai.ChatCompletion.create. These are specific function signatures that PromptLayer uses to parse the request_response. Some integration libraries use special function_name’s such as langchain.PromptLayerChatOpenAI.object
Keyword arguments that are passed into the LLM (such as OpenAI’s API). Normally it should include
engine and prompt at the very least. If you are using a chat completion or GPT-4, it should include messages instead of prompt.object
The LLM response. This response must be formatted exactly in OpenAI’s response format.
integer
The time at which the LLM request was initiated.
integer
The time at which the LLM request was completed.
array
An array of string tags to tag this request on the PromptLayer dashboard.
string
The ID of the prompt in the PromptLayer Registry that you used for this request (see
/prompt-templates/{prompt_name} on how to get this id or you can get it from the URL in the dashboard).object
The input variables you used for a template. This is used for syntax highlighting and, more importantly used, for backtesting when you want to iterate a prompt.
integer
It is the version of the prompt that you are trying to track. This should be an integer of a prompt that you are tracking.
string
The API key for authentication.
Was this page helpful?
⌘I

