> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracelm.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions

> OpenAI-compatible chat completions with TraceLM tracing and reliability context

OpenAI-compatible endpoint with tracing and reliability metadata capture.

## Required Headers

* `X-API-Key: lt_...`
* `Authorization: Bearer <provider_key>`
* `Content-Type: application/json`

## Optional Headers

* `X-Provider: openai | anthropic | google`
* `X-Task-ID`, `X-Task-Name`, `X-Conversation-ID`, `X-User-ID`

## Request Body

Pass standard OpenAI Chat Completions payload fields (`model`, `messages`, `tools`, `temperature`, `max_tokens`, `stream`, etc.).

## Example

```bash theme={null}
curl -X POST "https://api.tracelm.ai/v1/chat/completions" \
  -H "X-API-Key: $TRACELM_API_KEY" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "X-Provider: openai" \
  -H "X-Task-ID: 550e8400-e29b-41d4-a716-446655440000" \
  -H "X-Conversation-ID: 660e8400-e29b-41d4-a716-446655440000" \
  -H "X-User-ID: user_123" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"Find me flights to NYC"}],
    "tools": []
  }'
```

## Response

Returns OpenAI-compatible response shape. Trace and task-level metrics are available through `/api/v1/tasks/*` and `/api/v1/conversations/*`.
