Skip to main content

Request Tracing

When you need the Turing Platform team to help diagnose an issue, or want to trace a specific request, you will need to provide a request identifier. The platform offers two:

HeaderDirectionDescription
X-Turing-Trace-IdResponseRequest trace ID returned by the Turing Platform (passively obtained)
X-Client-Request-IdRequestRequest ID set by the client (actively set)

Both can be used together — in production environments it is recommended to enable both simultaneously.

Full Header List

In addition to the Trace ID, the platform returns observability headers on responses that include the actual model used, retry/fallback counts, and processing latency. For definitions of all request/response headers, see Headers Protocol.


Passive: Reading the Trace ID from the Response

The Turing Platform includes X-Turing-Trace-Id in the headers of every response.

SDK

from openai import OpenAI

client = OpenAI()

# Use with_raw_response to access the raw response
response = client.chat.completions.with_raw_response.create(
model="turing/gpt-4.1",
messages=[{"role": "user", "content": "Hello!"}]
)

# Retrieve the Trace ID from the headers
trace_id = response.headers.get("x-turing-trace-id")
print(f"Trace ID: {trace_id}")

# Parse the response body
completion = response.parse()

cURL

curl -i $TURING_BASE_URL/chat/completions \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "turing/gpt-4.1",
"messages": [{"role": "user", "content": "Hello!"}]
}'

# The response headers will include:
# x-turing-trace-id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

In addition to the Trace ID, non-streaming responses also include observability headers such as x-turing-model-id, x-turing-retries, and x-turing-fallbacks, which confirm the actual model that served the request along with retry/fallback details — see Headers Protocol.


Active: Setting a Client Request ID

When a request fails (network timeout, connection dropped), the client may never receive the response headers. In such cases there is no Trace ID to retrieve. By proactively setting X-Client-Request-Id on the request, you can use that ID to investigate issues regardless of whether the request succeeds or fails.

SDK

import uuid
from openai import OpenAI

client = OpenAI()

# Generate a unique Request ID
client_request_id = str(uuid.uuid4())
print(f"Client Request ID: {client_request_id}")

try:
completion = client.chat.completions.create(
model="turing/gpt-4.1",
messages=[{"role": "user", "content": "Hello!"}],
extra_headers={
"X-Client-Request-Id": client_request_id
}
)
except Exception as e:
# Even if the request fails, use client_request_id to investigate
print(f"Request failed. Please contact the Turing Platform and provide Client Request ID: {client_request_id}")
raise

cURL

# Generate a UUID first
CLIENT_REQUEST_ID=$(uuidgen)
echo "Client Request ID: $CLIENT_REQUEST_ID"

curl $TURING_BASE_URL/chat/completions \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Client-Request-Id: $CLIENT_REQUEST_ID" \
-d '{
"model": "turing/gpt-4.1",
"messages": [{"role": "user", "content": "Hello!"}]
}'

Quick Reference by Scenario

ScenarioWhich ID to use
Request succeeded; need to investigate response content or billingX-Turing-Trace-Id from response headers
Request failed / timed out / no response receivedX-Client-Request-Id set on the request
Tracing a business workflow over an extended periodUse both, and write them to your application logs

Production Best Practices

We recommend setting X-Client-Request-Id on every request in production and logging both IDs to your application logs for easy correlation later.

import uuid
import logging
from openai import OpenAI

client = OpenAI()
logger = logging.getLogger(__name__)

def call_llm(messages):
client_request_id = str(uuid.uuid4())

try:
response = client.chat.completions.with_raw_response.create(
model="turing/gpt-4.1",
messages=messages,
extra_headers={
"X-Client-Request-Id": client_request_id
}
)

trace_id = response.headers.get("x-turing-trace-id")
logger.info(
"LLM call success, client_request_id=%s, trace_id=%s",
client_request_id, trace_id,
)

return response.parse()

except Exception as e:
logger.error(
"LLM call failed, client_request_id=%s, error=%s",
client_request_id, e,
)
raise

With this approach, whether a request succeeds or fails, you can quickly locate issues using the IDs recorded in your logs.


See also