OpenAILLMTracingAdapter
Tracing adapter for OpenAI API.
Automatically detects and handles multiple OpenAI API endpoints including chat completions, responses API, and image operations (generation, editing). Uses specialized handlers for each endpoint type to extract telemetry data including model parameters, messages, tool calls, streaming, and media content.
Supported Endpoints
Chat Completions:
/v1/chat/completionsResponses API:
/v1/responsesImage Generation:
/v1/images/generationsImage Editing:
/v1/images/edits
Example Usage
val client = instrument(HttpClient(), OpenAILLMTracingAdapter())
// Chat completions
client.post("https://api.openai.com/v1/chat/completions") {
header("Authorization", "Bearer $apiKey")
setBody("""
{
"messages": [{"role": "user", "content": "Hello!"}],
"model": "gpt-4o-mini"
}
""")
}
// Automatically detects endpoint and traces accordinglyContent copied to clipboard
See: OpenAI API Reference