Home / AI & GenAI

AI & GenAITroubleshootingBeginner

Opening a support ticket for a failed LLM call: capture request IDs, headers and debug logs from the OpenAI SDK, Azure OpenAI and boto3

Get the request ID, response headers and SDK debug logs for a failing OpenAI, Azure OpenAI or Bedrock call, so the vendor's support team can find your request on their side.

Deepak Bhardwaj6 min read

Applies toOpenAI Python SDK 1.x and later (OpenAI and Azure OpenAI), boto3 / botocore (Amazon Bedrock Runtime), AWS CLI v2, curl

The symptom

A call to an LLM API fails or behaves strangely: a 500, a 429 you can't explain, an answer cut off halfway, or a latency spike. You open a ticket with the vendor and the first reply is "please send the request ID, timestamp and region".

Without a request ID, support has to search by time window and account, which takes days. With one, they can usually find the exact request. This post shows where each SDK exposes the ID and headers, and how to turn on debug logging without leaking secrets into the ticket.

What to collect

Item Why support needs it Where it comes from
Request ID Finds the exact request in their logs Response header or SDK attribute
UTC timestamp Narrows the search window Your log line or the date header
Endpoint and region Routes the ticket to the right team Base URL, client region, region headers
Model or deployment name Separates model issues from platform issues Your request
HTTP status and error body Shows what the service said Exception object
Rate-limit headers Explains 429s Response headers

Collect several failing request IDs if the problem is intermittent. One ID proves that a request failed; ten show a pattern.

OpenAI Python SDK

Successful responses

Response objects carry the request ID from the x-request-id header:

from openai import OpenAI

client = OpenAI()
resp = client.chat.completions.create(
    model="gpt-4.1-mini",
    messages=[{"role": "user", "content": "ping"}],
)
print(resp._request_id)

The leading underscore is part of the documented name; it's there to avoid clashing with response fields.

All headers, including rate limits

Use with_raw_response to get the HTTP response, then parse the body yourself:

raw = client.chat.completions.with_raw_response.create(
    model="gpt-4.1-mini",
    messages=[{"role": "user", "content": "ping"}],
)
for h in ("x-request-id", "openai-processing-ms",
          "x-ratelimit-remaining-requests", "x-ratelimit-remaining-tokens", "date"):
    print(h, raw.headers.get(h))
completion = raw.parse()

Failed calls

API errors raise openai.APIStatusError (or a subclass such as RateLimitError), which carries the status, the request ID and the full response:

import openai, logging

try:
    client.chat.completions.create(model="gpt-4.1-mini",
                                   messages=[{"role": "user", "content": "ping"}])
except openai.APIStatusError as e:
    logging.error("status=%s request_id=%s body=%s retry_after=%s",
                  e.status_code, e.request_id, e.response.text,
                  e.response.headers.get("retry-after"))
    raise
except openai.APIConnectionError as e:
    logging.error("no response from server: %r", e)
    raise

An APIConnectionError or timeout has no request ID because the server never answered. That points at DNS, proxies, TLS or network, not the model service, and the ticket belongs with your network team first.

SDK debug logging

Set an environment variable to log every request, retry and response status:

export OPENAI_LOG=debug
python app.py 2> openai-debug.log

PowerShell:

$env:OPENAI_LOG = "debug"
python app.py 2> openai-debug.log

The debug log shows retries clearly, which matters: the error you see may be the last of several attempts, each with its own request ID.

Azure OpenAI

The same SDK works through AzureOpenAI, so _request_id, with_raw_response and APIStatusError behave as above. Azure adds its own headers; the most useful for a ticket is apim-request-id:

from openai import AzureOpenAI
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

token = get_bearer_token_provider(DefaultAzureCredential(),
                                  "https://cognitiveservices.azure.com/.default")
client = AzureOpenAI(azure_endpoint="https://myaoai.openai.azure.com",
                     azure_ad_token_provider=token, api_version="2024-10-21")

raw = client.chat.completions.with_raw_response.create(
    model="chat-prod",  # deployment name
    messages=[{"role": "user", "content": "ping"}],
)
for h in ("apim-request-id", "x-request-id", "x-ms-region", "date"):
    print(h, raw.headers.get(h))

Header names vary with the deployment type and API version; print all of them once (dict(raw.headers)) and note which ones your resource returns. Include the resource name, deployment name, deployment type (Standard, Global, Data Zone, Provisioned) and API version in the ticket.

If an API Management gateway sits in front, the request ID you see may belong to your gateway rather than to Azure OpenAI. Log the backend response headers in APIM, or reproduce the call directly against the resource, so you can give support the backend ID.

Amazon Bedrock with boto3

Every boto3 response includes ResponseMetadata:

import boto3, logging
from botocore.exceptions import ClientError

client = boto3.client("bedrock-runtime", region_name="eu-west-1")
try:
    resp = client.converse(
        modelId="<model-or-inference-profile-id>",
        messages=[{"role": "user", "content": [{"text": "ping"}]}],
    )
    print(resp["ResponseMetadata"]["RequestId"], resp["usage"])
except ClientError as e:
    meta = e.response["ResponseMetadata"]
    logging.error("code=%s msg=%s request_id=%s http=%s",
                  e.response["Error"]["Code"], e.response["Error"]["Message"],
                  meta.get("RequestId"), meta.get("HTTPStatusCode"))
    raise

ResponseMetadata["HTTPHeaders"] holds the raw headers if support asks for them.

For wire-level detail, turn on botocore debug logging for one test run:

boto3.set_stream_logger("botocore", logging.DEBUG)

From the CLI, --debug does the same for a single call:

aws bedrock-runtime converse --region eu-west-1 \
  --model-id <model-or-inference-profile-id> \
  --messages '[{"role":"user","content":[{"text":"ping"}]}]' \
  --debug 2> bedrock-debug.log

Include the Region, account ID, model or inference profile ID and the request ID. For cross-Region inference profiles, say so in the ticket, because the request may have been served from another Region.

Reproducing with curl

A minimal curl reproduction rules out your SDK and app code. Print response headers with -i, not -v, so the request's Authorization header doesn't end up in your terminal history or ticket:

curl -sS -i https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4.1-mini","messages":[{"role":"user","content":"ping"}]}' \
  | grep -iE '^(HTTP|x-request-id|date|retry-after|x-ratelimit)'

If curl succeeds and the SDK fails from the same host, compare timeouts, proxy settings and retries before opening a ticket.

Caution

Debug logs and -v output can contain API keys, bearer tokens, signed AWS headers, prompts and model output. Never attach them to a ticket unedited. Remove credentials and customer data first, and share only the lines support asks for.

Prevent it next time

  • Log the request ID, status, model and latency on every LLM call in production, not just failures. You can't get the ID back after the fact.
  • Add the request ID as an attribute on your OpenTelemetry span for the call, so traces and tickets point at the same request.
  • Log each retry attempt with its own request ID, so you can tell support "five attempts, all 500" rather than "it failed".
  • Keep a short ticket template in your runbook: request IDs, UTC times, endpoint, Region, model or deployment, SDK version (pip show openai boto3), status codes and error bodies.
  • Keep debug logging off in production; turn it on for a single reproduction and delete the log afterwards.