Response Headers¶
LLMGW includes custom response headers prefixed with x-llmgw- that provide valuable metadata about each request.
Quick Reference¶
| Header | Purpose | Example |
|---|---|---|
x-llmgw-request-id |
Unique request identifier for debugging | 3cb26481-d869-4923-8093-3feb92f8d9fc |
x-llmgw-model-id |
Actual model used (may differ due to load balancing) | azure-us-gpt35 |
x-llmgw-cost |
Request cost in USD | 0.00012 |
x-llmgw-attempts |
Number of retry attempts | 1 |
x-llmgw-remaining-limits |
Remaining usage limits | user/daily-tokens/9500 |
Accessing Headers¶
With curl¶
Use the -i flag to see all response headers:
curl -i "https://<llmgw-deployment-url>/openai/v1/chat/completions" \
-H "Authorization: Bearer <YOUR_LLMGW_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4.1", "messages": [{"role": "user", "content": "What is the weather like?"}]}'
With OpenAI Client (Python)¶
import json
response = client.chat.with_raw_response.completions.create(
model="gpt-4.1",
messages=[{"role": "user", "content": "What is the weather like?"}]
)
# Extract LLMGW headers
llmgw_headers = {
key: value
for key, value in response.headers.items()
if key.startswith('x-llmgw')
}
print(json.dumps(llmgw_headers, indent=2))
With Langchain¶
from langchain_openai import AzureChatOpenAI
model = AzureChatOpenAI(
# ... configuration
include_response_headers=True
)
response = model.invoke("What is the weather like?")
if hasattr(response, 'response_metadata'):
headers = response.response_metadata.get('headers', {})
llmgw_headers = {
key: value
for key, value in headers.items()
if key.startswith('x-llmgw')
}
print(llmgw_headers)
Example Response¶
{
"x-llmgw-request-id": "3cb26481-d869-4923-8093-3feb92f8d9fc",
"x-llmgw-model-id": "azure-us-gpt35",
"x-llmgw-attempts": "1",
"x-llmgw-cost": "0.00012",
"x-llmgw-remaining-limits": "user/daily-requests/4999"
}
Use Cases¶
- Cost Tracking: Monitor spending with
x-llmgw-cost - Debugging: Use
x-llmgw-request-idto trace requests in logs - Load Balancing: Check
x-llmgw-model-idto see which model actually processed your request - Reliability: Monitor
x-llmgw-attemptsto understand retry patterns - Usage Management: Track remaining limits with
x-llmgw-remaining-limits
Notes¶
- Headers are returned for both successful and failed requests (when possible)
x-llmgw-remaining-limitsmay appear multiple times if multiple limits apply- All cost values are in USD