curl --request POST \
--url https://api.promptlayer.com/v1/traces \
--header 'Content-Type: <content-type>' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "my-llm-app"
}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "openai.instrumentation",
"version": "1.0.0"
},
"spans": [
{
"traceId": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"spanId": "1a2b3c4d5e6f7a8b",
"name": "chat gpt-4",
"kind": 3,
"startTimeUnixNano": "1700000000000000000",
"endTimeUnixNano": "1700000001500000000",
"attributes": [
{
"key": "gen_ai.request.model",
"value": {
"stringValue": "gpt-4"
}
},
{
"key": "gen_ai.provider.name",
"value": {
"stringValue": "openai"
}
},
{
"key": "gen_ai.usage.input_tokens",
"value": {
"intValue": "25"
}
},
{
"key": "gen_ai.usage.output_tokens",
"value": {
"intValue": "120"
}
}
],
"status": {
"code": 1
}
}
]
}
]
}
]
}
'import requests
url = "https://api.promptlayer.com/v1/traces"
payload = { "resourceSpans": [
{
"resource": { "attributes": [
{
"key": "service.name",
"value": { "stringValue": "my-llm-app" }
}
] },
"scopeSpans": [
{
"scope": {
"name": "openai.instrumentation",
"version": "1.0.0"
},
"spans": [
{
"traceId": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"spanId": "1a2b3c4d5e6f7a8b",
"name": "chat gpt-4",
"kind": 3,
"startTimeUnixNano": "1700000000000000000",
"endTimeUnixNano": "1700000001500000000",
"attributes": [
{
"key": "gen_ai.request.model",
"value": { "stringValue": "gpt-4" }
},
{
"key": "gen_ai.provider.name",
"value": { "stringValue": "openai" }
},
{
"key": "gen_ai.usage.input_tokens",
"value": { "intValue": "25" }
},
{
"key": "gen_ai.usage.output_tokens",
"value": { "intValue": "120" }
}
],
"status": { "code": 1 }
}
]
}
]
}
] }
headers = {
"Content-Type": "<content-type>",
"X-API-KEY": "<api-key>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', 'X-API-KEY': '<api-key>'},
body: JSON.stringify({
resourceSpans: [
{
resource: {attributes: [{key: 'service.name', value: {stringValue: 'my-llm-app'}}]},
scopeSpans: [
{
scope: {name: 'openai.instrumentation', version: '1.0.0'},
spans: [
{
traceId: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6',
spanId: '1a2b3c4d5e6f7a8b',
name: 'chat gpt-4',
kind: 3,
startTimeUnixNano: '1700000000000000000',
endTimeUnixNano: '1700000001500000000',
attributes: [
{key: 'gen_ai.request.model', value: {stringValue: 'gpt-4'}},
{key: 'gen_ai.provider.name', value: {stringValue: 'openai'}},
{key: 'gen_ai.usage.input_tokens', value: {intValue: '25'}},
{key: 'gen_ai.usage.output_tokens', value: {intValue: '120'}}
],
status: {code: 1}
}
]
}
]
}
]
})
};
fetch('https://api.promptlayer.com/v1/traces', 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/v1/traces",
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([
'resourceSpans' => [
[
'resource' => [
'attributes' => [
[
'key' => 'service.name',
'value' => [
'stringValue' => 'my-llm-app'
]
]
]
],
'scopeSpans' => [
[
'scope' => [
'name' => 'openai.instrumentation',
'version' => '1.0.0'
],
'spans' => [
[
'traceId' => 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6',
'spanId' => '1a2b3c4d5e6f7a8b',
'name' => 'chat gpt-4',
'kind' => 3,
'startTimeUnixNano' => '1700000000000000000',
'endTimeUnixNano' => '1700000001500000000',
'attributes' => [
[
'key' => 'gen_ai.request.model',
'value' => [
'stringValue' => 'gpt-4'
]
],
[
'key' => 'gen_ai.provider.name',
'value' => [
'stringValue' => 'openai'
]
],
[
'key' => 'gen_ai.usage.input_tokens',
'value' => [
'intValue' => '25'
]
],
[
'key' => 'gen_ai.usage.output_tokens',
'value' => [
'intValue' => '120'
]
]
],
'status' => [
'code' => 1
]
]
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"X-API-KEY: <api-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.promptlayer.com/v1/traces"
payload := strings.NewReader("{\n \"resourceSpans\": [\n {\n \"resource\": {\n \"attributes\": [\n {\n \"key\": \"service.name\",\n \"value\": {\n \"stringValue\": \"my-llm-app\"\n }\n }\n ]\n },\n \"scopeSpans\": [\n {\n \"scope\": {\n \"name\": \"openai.instrumentation\",\n \"version\": \"1.0.0\"\n },\n \"spans\": [\n {\n \"traceId\": \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\",\n \"spanId\": \"1a2b3c4d5e6f7a8b\",\n \"name\": \"chat gpt-4\",\n \"kind\": 3,\n \"startTimeUnixNano\": \"1700000000000000000\",\n \"endTimeUnixNano\": \"1700000001500000000\",\n \"attributes\": [\n {\n \"key\": \"gen_ai.request.model\",\n \"value\": {\n \"stringValue\": \"gpt-4\"\n }\n },\n {\n \"key\": \"gen_ai.provider.name\",\n \"value\": {\n \"stringValue\": \"openai\"\n }\n },\n {\n \"key\": \"gen_ai.usage.input_tokens\",\n \"value\": {\n \"intValue\": \"25\"\n }\n },\n {\n \"key\": \"gen_ai.usage.output_tokens\",\n \"value\": {\n \"intValue\": \"120\"\n }\n }\n ],\n \"status\": {\n \"code\": 1\n }\n }\n ]\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("X-API-KEY", "<api-key>")
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/v1/traces")
.header("Content-Type", "<content-type>")
.header("X-API-KEY", "<api-key>")
.body("{\n \"resourceSpans\": [\n {\n \"resource\": {\n \"attributes\": [\n {\n \"key\": \"service.name\",\n \"value\": {\n \"stringValue\": \"my-llm-app\"\n }\n }\n ]\n },\n \"scopeSpans\": [\n {\n \"scope\": {\n \"name\": \"openai.instrumentation\",\n \"version\": \"1.0.0\"\n },\n \"spans\": [\n {\n \"traceId\": \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\",\n \"spanId\": \"1a2b3c4d5e6f7a8b\",\n \"name\": \"chat gpt-4\",\n \"kind\": 3,\n \"startTimeUnixNano\": \"1700000000000000000\",\n \"endTimeUnixNano\": \"1700000001500000000\",\n \"attributes\": [\n {\n \"key\": \"gen_ai.request.model\",\n \"value\": {\n \"stringValue\": \"gpt-4\"\n }\n },\n {\n \"key\": \"gen_ai.provider.name\",\n \"value\": {\n \"stringValue\": \"openai\"\n }\n },\n {\n \"key\": \"gen_ai.usage.input_tokens\",\n \"value\": {\n \"intValue\": \"25\"\n }\n },\n {\n \"key\": \"gen_ai.usage.output_tokens\",\n \"value\": {\n \"intValue\": \"120\"\n }\n }\n ],\n \"status\": {\n \"code\": 1\n }\n }\n ]\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.promptlayer.com/v1/traces")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["X-API-KEY"] = '<api-key>'
request.body = "{\n \"resourceSpans\": [\n {\n \"resource\": {\n \"attributes\": [\n {\n \"key\": \"service.name\",\n \"value\": {\n \"stringValue\": \"my-llm-app\"\n }\n }\n ]\n },\n \"scopeSpans\": [\n {\n \"scope\": {\n \"name\": \"openai.instrumentation\",\n \"version\": \"1.0.0\"\n },\n \"spans\": [\n {\n \"traceId\": \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\",\n \"spanId\": \"1a2b3c4d5e6f7a8b\",\n \"name\": \"chat gpt-4\",\n \"kind\": 3,\n \"startTimeUnixNano\": \"1700000000000000000\",\n \"endTimeUnixNano\": \"1700000001500000000\",\n \"attributes\": [\n {\n \"key\": \"gen_ai.request.model\",\n \"value\": {\n \"stringValue\": \"gpt-4\"\n }\n },\n {\n \"key\": \"gen_ai.provider.name\",\n \"value\": {\n \"stringValue\": \"openai\"\n }\n },\n {\n \"key\": \"gen_ai.usage.input_tokens\",\n \"value\": {\n \"intValue\": \"25\"\n }\n },\n {\n \"key\": \"gen_ai.usage.output_tokens\",\n \"value\": {\n \"intValue\": \"120\"\n }\n }\n ],\n \"status\": {\n \"code\": 1\n }\n }\n ]\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"partialSuccess": null
}Ingest Traces (OTLP)
curl --request POST \
--url https://api.promptlayer.com/v1/traces \
--header 'Content-Type: <content-type>' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "my-llm-app"
}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "openai.instrumentation",
"version": "1.0.0"
},
"spans": [
{
"traceId": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"spanId": "1a2b3c4d5e6f7a8b",
"name": "chat gpt-4",
"kind": 3,
"startTimeUnixNano": "1700000000000000000",
"endTimeUnixNano": "1700000001500000000",
"attributes": [
{
"key": "gen_ai.request.model",
"value": {
"stringValue": "gpt-4"
}
},
{
"key": "gen_ai.provider.name",
"value": {
"stringValue": "openai"
}
},
{
"key": "gen_ai.usage.input_tokens",
"value": {
"intValue": "25"
}
},
{
"key": "gen_ai.usage.output_tokens",
"value": {
"intValue": "120"
}
}
],
"status": {
"code": 1
}
}
]
}
]
}
]
}
'import requests
url = "https://api.promptlayer.com/v1/traces"
payload = { "resourceSpans": [
{
"resource": { "attributes": [
{
"key": "service.name",
"value": { "stringValue": "my-llm-app" }
}
] },
"scopeSpans": [
{
"scope": {
"name": "openai.instrumentation",
"version": "1.0.0"
},
"spans": [
{
"traceId": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"spanId": "1a2b3c4d5e6f7a8b",
"name": "chat gpt-4",
"kind": 3,
"startTimeUnixNano": "1700000000000000000",
"endTimeUnixNano": "1700000001500000000",
"attributes": [
{
"key": "gen_ai.request.model",
"value": { "stringValue": "gpt-4" }
},
{
"key": "gen_ai.provider.name",
"value": { "stringValue": "openai" }
},
{
"key": "gen_ai.usage.input_tokens",
"value": { "intValue": "25" }
},
{
"key": "gen_ai.usage.output_tokens",
"value": { "intValue": "120" }
}
],
"status": { "code": 1 }
}
]
}
]
}
] }
headers = {
"Content-Type": "<content-type>",
"X-API-KEY": "<api-key>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', 'X-API-KEY': '<api-key>'},
body: JSON.stringify({
resourceSpans: [
{
resource: {attributes: [{key: 'service.name', value: {stringValue: 'my-llm-app'}}]},
scopeSpans: [
{
scope: {name: 'openai.instrumentation', version: '1.0.0'},
spans: [
{
traceId: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6',
spanId: '1a2b3c4d5e6f7a8b',
name: 'chat gpt-4',
kind: 3,
startTimeUnixNano: '1700000000000000000',
endTimeUnixNano: '1700000001500000000',
attributes: [
{key: 'gen_ai.request.model', value: {stringValue: 'gpt-4'}},
{key: 'gen_ai.provider.name', value: {stringValue: 'openai'}},
{key: 'gen_ai.usage.input_tokens', value: {intValue: '25'}},
{key: 'gen_ai.usage.output_tokens', value: {intValue: '120'}}
],
status: {code: 1}
}
]
}
]
}
]
})
};
fetch('https://api.promptlayer.com/v1/traces', 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/v1/traces",
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([
'resourceSpans' => [
[
'resource' => [
'attributes' => [
[
'key' => 'service.name',
'value' => [
'stringValue' => 'my-llm-app'
]
]
]
],
'scopeSpans' => [
[
'scope' => [
'name' => 'openai.instrumentation',
'version' => '1.0.0'
],
'spans' => [
[
'traceId' => 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6',
'spanId' => '1a2b3c4d5e6f7a8b',
'name' => 'chat gpt-4',
'kind' => 3,
'startTimeUnixNano' => '1700000000000000000',
'endTimeUnixNano' => '1700000001500000000',
'attributes' => [
[
'key' => 'gen_ai.request.model',
'value' => [
'stringValue' => 'gpt-4'
]
],
[
'key' => 'gen_ai.provider.name',
'value' => [
'stringValue' => 'openai'
]
],
[
'key' => 'gen_ai.usage.input_tokens',
'value' => [
'intValue' => '25'
]
],
[
'key' => 'gen_ai.usage.output_tokens',
'value' => [
'intValue' => '120'
]
]
],
'status' => [
'code' => 1
]
]
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"X-API-KEY: <api-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.promptlayer.com/v1/traces"
payload := strings.NewReader("{\n \"resourceSpans\": [\n {\n \"resource\": {\n \"attributes\": [\n {\n \"key\": \"service.name\",\n \"value\": {\n \"stringValue\": \"my-llm-app\"\n }\n }\n ]\n },\n \"scopeSpans\": [\n {\n \"scope\": {\n \"name\": \"openai.instrumentation\",\n \"version\": \"1.0.0\"\n },\n \"spans\": [\n {\n \"traceId\": \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\",\n \"spanId\": \"1a2b3c4d5e6f7a8b\",\n \"name\": \"chat gpt-4\",\n \"kind\": 3,\n \"startTimeUnixNano\": \"1700000000000000000\",\n \"endTimeUnixNano\": \"1700000001500000000\",\n \"attributes\": [\n {\n \"key\": \"gen_ai.request.model\",\n \"value\": {\n \"stringValue\": \"gpt-4\"\n }\n },\n {\n \"key\": \"gen_ai.provider.name\",\n \"value\": {\n \"stringValue\": \"openai\"\n }\n },\n {\n \"key\": \"gen_ai.usage.input_tokens\",\n \"value\": {\n \"intValue\": \"25\"\n }\n },\n {\n \"key\": \"gen_ai.usage.output_tokens\",\n \"value\": {\n \"intValue\": \"120\"\n }\n }\n ],\n \"status\": {\n \"code\": 1\n }\n }\n ]\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("X-API-KEY", "<api-key>")
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/v1/traces")
.header("Content-Type", "<content-type>")
.header("X-API-KEY", "<api-key>")
.body("{\n \"resourceSpans\": [\n {\n \"resource\": {\n \"attributes\": [\n {\n \"key\": \"service.name\",\n \"value\": {\n \"stringValue\": \"my-llm-app\"\n }\n }\n ]\n },\n \"scopeSpans\": [\n {\n \"scope\": {\n \"name\": \"openai.instrumentation\",\n \"version\": \"1.0.0\"\n },\n \"spans\": [\n {\n \"traceId\": \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\",\n \"spanId\": \"1a2b3c4d5e6f7a8b\",\n \"name\": \"chat gpt-4\",\n \"kind\": 3,\n \"startTimeUnixNano\": \"1700000000000000000\",\n \"endTimeUnixNano\": \"1700000001500000000\",\n \"attributes\": [\n {\n \"key\": \"gen_ai.request.model\",\n \"value\": {\n \"stringValue\": \"gpt-4\"\n }\n },\n {\n \"key\": \"gen_ai.provider.name\",\n \"value\": {\n \"stringValue\": \"openai\"\n }\n },\n {\n \"key\": \"gen_ai.usage.input_tokens\",\n \"value\": {\n \"intValue\": \"25\"\n }\n },\n {\n \"key\": \"gen_ai.usage.output_tokens\",\n \"value\": {\n \"intValue\": \"120\"\n }\n }\n ],\n \"status\": {\n \"code\": 1\n }\n }\n ]\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.promptlayer.com/v1/traces")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["X-API-KEY"] = '<api-key>'
request.body = "{\n \"resourceSpans\": [\n {\n \"resource\": {\n \"attributes\": [\n {\n \"key\": \"service.name\",\n \"value\": {\n \"stringValue\": \"my-llm-app\"\n }\n }\n ]\n },\n \"scopeSpans\": [\n {\n \"scope\": {\n \"name\": \"openai.instrumentation\",\n \"version\": \"1.0.0\"\n },\n \"spans\": [\n {\n \"traceId\": \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\",\n \"spanId\": \"1a2b3c4d5e6f7a8b\",\n \"name\": \"chat gpt-4\",\n \"kind\": 3,\n \"startTimeUnixNano\": \"1700000000000000000\",\n \"endTimeUnixNano\": \"1700000001500000000\",\n \"attributes\": [\n {\n \"key\": \"gen_ai.request.model\",\n \"value\": {\n \"stringValue\": \"gpt-4\"\n }\n },\n {\n \"key\": \"gen_ai.provider.name\",\n \"value\": {\n \"stringValue\": \"openai\"\n }\n },\n {\n \"key\": \"gen_ai.usage.input_tokens\",\n \"value\": {\n \"intValue\": \"25\"\n }\n },\n {\n \"key\": \"gen_ai.usage.output_tokens\",\n \"value\": {\n \"intValue\": \"120\"\n }\n }\n ],\n \"status\": {\n \"code\": 1\n }\n }\n ]\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"partialSuccess": null
}Behavior Notes
- This endpoint accepts an
ExportTraceServiceRequestas defined by the OpenTelemetry specification. - Spans carrying GenAI semantic convention attributes are automatically converted into PromptLayer request logs.
- Supported content types are
application/x-protobuffor binary protobuf encoding andapplication/jsonfor JSON encoding. - Gzip
Content-Encodingis supported for both formats. - Spans can include
promptlayer.prompt.name, optionally withpromptlayer.prompt.version, to link the generated request log to an existing prompt template in your workspace. - Spans can include
user.id/enduser.id,gen_ai.conversation.id/session.id, andpromptlayer.metadata.*attributes to attach searchable user identity and metadata to the generated request log. - For SDK setup, GenAI semantic conventions, prompt template linking, metadata, and collector configuration, see OpenTelemetry.
Related
Authorizations
Headers
The encoding of the request body. Use application/x-protobuf for binary protobuf or application/json for JSON.
application/x-protobuf, application/json Set to gzip if the request body is gzip-compressed.
gzip Query Parameters
When true, all trace IDs in the request are marked as closed after ingestion. Subsequent span writes for those traces will be rejected with HTTP 409. Defaults to false.
Body
An OTLP ExportTraceServiceRequest in JSON encoding. See the OTLP specification for the full schema.
An array of ResourceSpans. Each element describes spans from a single instrumented resource.
Show child attributes
Show child attributes
Response
Successful Response. When using protobuf, the response is a binary ExportTraceServiceResponse. When using JSON, the response is a JSON object.
Response to an OTLP trace export request.
Present only when some spans were rejected. Null when all spans were accepted.
Show child attributes
Show child attributes
Was this page helpful?

