curl -X POST 'https://app.langtrace.ai/api/trace' \
-H 'Content-Type: application/json' \
-H 'User-Agent: opentelemetry-python' \
-H 'x-api-key: <LANGTRACE_API_KEY>' \
--data-raw '{
"resourceSpans": [{
"resource": {
"attributes": {
"service.name": {
"stringValue": "my-ai-service"
},
"service.version": {
"stringValue": "1.0.0"
}
}
},
"scopeSpans": [{
"spans": [{
"traceId": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"spanId": "1234567890abcdef",
"name": "OpenAI ChatCompletion",
"kind": 1,
"startTimeUnixNano": "1701555555000000000",
"endTimeUnixNano": "1701555557000000000",
"attributes": {
"llm.vendor": {
"stringValue": "openai"
},
"llm.request.model": {
"stringValue": "gpt-3.5-turbo"
},
"llm.request.type": {
"stringValue": "chat_completion"
},
"llm.request.messages": {
"stringValue": "[{\"role\":\"user\",\"content\":\"Hello, how are you?\"}]"
},
"llm.response.choices": {
"stringValue": "[{\"role\":\"assistant\",\"content\":\"I'm doing well, thank you for asking!\"}]"
}
}
}]
}]
}]
}'
import json
import requests
url = 'https://app.langtrace.ai/api/trace'
headers = {
'Content-Type': 'application/json',
'User-Agent': 'opentelemetry-python',
'x-api-key': '<LANGTRACE_API_KEY>'
}
payload = {
"resourceSpans": [{
"resource": {
"attributes": {
"service.name": {"stringValue": "my-ai-service"},
"service.version": {"stringValue": "1.0.0"}
}
},
"scopeSpans": [{
"spans": [{
"traceId": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"spanId": "1234567890abcdef",
"name": "OpenAI ChatCompletion",
"kind": 1,
"startTimeUnixNano": "1701555555000000000",
"endTimeUnixNano": "1701555557000000000",
"attributes": {
"llm.vendor": {"stringValue": "openai"},
"llm.request.model": {"stringValue": "gpt-3.5-turbo"},
"llm.request.type": {"stringValue": "chat_completion"},
"llm.request.messages": {"stringValue": json.dumps([{"role": "user", "content": "Hello, how are you?"}])},
"llm.response.choices": {"stringValue": json.dumps([{"role": "assistant", "content": "I'm doing well, thank you for asking!"}])}
}
}]
}]
}]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
{
"status": 200,
"message": "Traces received successfully"
}
{
"status": 401,
"message": "Invalid API key"
}
Traces API
Send Trace
Send OpenTelemetry-compatible traces to Langtrace
curl -X POST 'https://app.langtrace.ai/api/trace' \
-H 'Content-Type: application/json' \
-H 'User-Agent: opentelemetry-python' \
-H 'x-api-key: <LANGTRACE_API_KEY>' \
--data-raw '{
"resourceSpans": [{
"resource": {
"attributes": {
"service.name": {
"stringValue": "my-ai-service"
},
"service.version": {
"stringValue": "1.0.0"
}
}
},
"scopeSpans": [{
"spans": [{
"traceId": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"spanId": "1234567890abcdef",
"name": "OpenAI ChatCompletion",
"kind": 1,
"startTimeUnixNano": "1701555555000000000",
"endTimeUnixNano": "1701555557000000000",
"attributes": {
"llm.vendor": {
"stringValue": "openai"
},
"llm.request.model": {
"stringValue": "gpt-3.5-turbo"
},
"llm.request.type": {
"stringValue": "chat_completion"
},
"llm.request.messages": {
"stringValue": "[{\"role\":\"user\",\"content\":\"Hello, how are you?\"}]"
},
"llm.response.choices": {
"stringValue": "[{\"role\":\"assistant\",\"content\":\"I'm doing well, thank you for asking!\"}]"
}
}
}]
}]
}]
}'
import json
import requests
url = 'https://app.langtrace.ai/api/trace'
headers = {
'Content-Type': 'application/json',
'User-Agent': 'opentelemetry-python',
'x-api-key': '<LANGTRACE_API_KEY>'
}
payload = {
"resourceSpans": [{
"resource": {
"attributes": {
"service.name": {"stringValue": "my-ai-service"},
"service.version": {"stringValue": "1.0.0"}
}
},
"scopeSpans": [{
"spans": [{
"traceId": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"spanId": "1234567890abcdef",
"name": "OpenAI ChatCompletion",
"kind": 1,
"startTimeUnixNano": "1701555555000000000",
"endTimeUnixNano": "1701555557000000000",
"attributes": {
"llm.vendor": {"stringValue": "openai"},
"llm.request.model": {"stringValue": "gpt-3.5-turbo"},
"llm.request.type": {"stringValue": "chat_completion"},
"llm.request.messages": {"stringValue": json.dumps([{"role": "user", "content": "Hello, how are you?"}])},
"llm.response.choices": {"stringValue": json.dumps([{"role": "assistant", "content": "I'm doing well, thank you for asking!"}])}
}
}]
}]
}]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
{
"status": 200,
"message": "Traces received successfully"
}
{
"status": 401,
"message": "Invalid API key"
}
Send traces to Langtrace using the OpenTelemetry trace format. This endpoint accepts traces for various operations including OpenAI chat completions, function calls, and other LLM interactions.
Headers
string
required
Your Langtrace API key
string
required
Must be
application/jsonstring
required
Must be
opentelemetry-pythonBody
array
required
Array of resource spans containing trace data
object
required
Resource attributes identifying the service and environment
array
required
Array of scope spans containing individual operation traces
array
required
Array of spans representing individual operations
Request Example for OpenAI Chat Completion
curl -X POST 'https://app.langtrace.ai/api/trace' \
-H 'Content-Type: application/json' \
-H 'User-Agent: opentelemetry-python' \
-H 'x-api-key: <LANGTRACE_API_KEY>' \
--data-raw '{
"resourceSpans": [{
"resource": {
"attributes": {
"service.name": {
"stringValue": "my-ai-service"
},
"service.version": {
"stringValue": "1.0.0"
}
}
},
"scopeSpans": [{
"spans": [{
"traceId": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"spanId": "1234567890abcdef",
"name": "OpenAI ChatCompletion",
"kind": 1,
"startTimeUnixNano": "1701555555000000000",
"endTimeUnixNano": "1701555557000000000",
"attributes": {
"llm.vendor": {
"stringValue": "openai"
},
"llm.request.model": {
"stringValue": "gpt-3.5-turbo"
},
"llm.request.type": {
"stringValue": "chat_completion"
},
"llm.request.messages": {
"stringValue": "[{\"role\":\"user\",\"content\":\"Hello, how are you?\"}]"
},
"llm.response.choices": {
"stringValue": "[{\"role\":\"assistant\",\"content\":\"I'm doing well, thank you for asking!\"}]"
}
}
}]
}]
}]
}'
import json
import requests
url = 'https://app.langtrace.ai/api/trace'
headers = {
'Content-Type': 'application/json',
'User-Agent': 'opentelemetry-python',
'x-api-key': '<LANGTRACE_API_KEY>'
}
payload = {
"resourceSpans": [{
"resource": {
"attributes": {
"service.name": {"stringValue": "my-ai-service"},
"service.version": {"stringValue": "1.0.0"}
}
},
"scopeSpans": [{
"spans": [{
"traceId": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"spanId": "1234567890abcdef",
"name": "OpenAI ChatCompletion",
"kind": 1,
"startTimeUnixNano": "1701555555000000000",
"endTimeUnixNano": "1701555557000000000",
"attributes": {
"llm.vendor": {"stringValue": "openai"},
"llm.request.model": {"stringValue": "gpt-3.5-turbo"},
"llm.request.type": {"stringValue": "chat_completion"},
"llm.request.messages": {"stringValue": json.dumps([{"role": "user", "content": "Hello, how are you?"}])},
"llm.response.choices": {"stringValue": json.dumps([{"role": "assistant", "content": "I'm doing well, thank you for asking!"}])}
}
}]
}]
}]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
Response
number
HTTP status code (200 for success)
string
Success or error message
{
"status": 200,
"message": "Traces received successfully"
}
{
"status": 401,
"message": "Invalid API key"
}
Error Codes
string
Invalid or missing API key
string
Invalid request format or missing required fields
string
Internal server error
⌘I