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:
| Header | Direction | Description |
|---|---|---|
X-Turing-Trace-Id | Response | Request trace ID returned by the Turing Platform (passively obtained) |
X-Client-Request-Id | Request | Request ID set by the client (actively set) |
Both can be used together — in production environments it is recommended to enable both simultaneously.
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
| Scenario | Which ID to use |
|---|---|
| Request succeeded; need to investigate response content or billing | X-Turing-Trace-Id from response headers |
| Request failed / timed out / no response received | X-Client-Request-Id set on the request |
| Tracing a business workflow over an extended period | Use 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
- Headers Protocol — Definitions for all
X-Turing-*request/response headers - Timeouts, Retries, and Fallback — Configure request behavior under different error conditions
- Billing and Usage — How to look up billing details for a specific trace
- Troubleshooting → Timeouts and Model Instability — Typical timeout investigation workflow