OpenAI
Examples use Python. Beakpoint works with any language that OpenTelemetry supports.
Required OpenAI Attributes
The following cost calculation tags are required for traces originating from OpenAI API calls.
For a complete, runnable example, see Quill — Beakpoint's reference application for multi-model LLM cost attribution. Quill's tracing.py shows the full OTel setup, and roles.py defines the OpenAI models used.
Always Required Fields
These fields are always required for Beakpoint to calculate OpenAI costs:
| Attribute Name | Example Value | Allowed Values |
|---|---|---|
gen_ai.system | openai | openai (must be this exact value for direct OpenAI API calls; Azure OpenAI and Azure AI Foundry use their own gen_ai.system values — see GenAI Cost Tracking) |
gen_ai.request.model | gpt-4.1 | Any valid OpenAI model name |
gen_ai.usage.input_tokens | 512 | Non-negative integer |
gen_ai.usage.output_tokens | 128 | Non-negative integer |
gen_ai.systemThe OpenAI auto-instrumentor sets gen_ai.provider.name but not gen_ai.system. Beakpoint requires gen_ai.system for cost calculation. Use a custom SpanProcessor to copy gen_ai.provider.name to gen_ai.system when the span starts. See the _GenAiSystemProcessor pattern in Quill for a working example, or the Track LLM Costs guide for complete setup instructions.
Optional Enrichment Attributes
These fields are optional but improve cost accuracy when provided:
| Attribute Name | Example Value | Description |
|---|---|---|
gen_ai.response.model | gpt-4.1-2025-04-14 | The exact model version returned in the response. When present, this takes precedence over gen_ai.request.model for pricing lookups. |
gen_ai.usage.input_tokens.cached | 256 | Number of input tokens served from the prompt cache. Cached tokens are billed at a reduced rate. |
gen_ai.usage.output_tokens.reasoning | 64 | Number of tokens used for internal reasoning (o-series models). Billed at the standard output token rate. |
gen_ai.provider.name | openai | The provider name set by the OpenAI auto-instrumentor. The _GenAiSystemProcessor copies this to gen_ai.system (see note above). |
cloud.provider | openai | Provider identification for cloud resource tracking. Set automatically by the _GenAiSystemProcessor pattern. |
Supported Models
Beakpoint calculates costs for the following OpenAI models. Prices are per 1 million tokens (USD).
| Model | Input ($/M) | Cached Input ($/M) | Output ($/M) |
|---|---|---|---|
gpt-4.1 | $2.00 | $0.50 | $8.00 |
gpt-4.1-mini | $0.40 | $0.10 | $1.60 |
gpt-4.1-nano | $0.10 | $0.025 | $0.40 |
Prices reflect OpenAI list pricing as of the last documentation update. If you suspect pricing has changed, consult the OpenAI pricing page to verify. These same rates apply to OpenAI models accessed through Azure OpenAI and Azure AI Foundry.
Python Example
The quickest way to emit the required attributes is with the opentelemetry-instrumentation-openai-v2 package paired with a SpanProcessor that sets gen_ai.system. This example is adapted from Quill:
pip install opentelemetry-instrumentation-openai-v2
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
from openai import OpenAI
# Instrument before creating the client (see Track LLM Costs guide
# for the full TracerProvider setup including _GenAiSystemProcessor)
OpenAIInstrumentor().instrument()
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
)
The instrumentation automatically sets gen_ai.provider.name, gen_ai.request.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, and the optional enrichment attributes whenever they are available in the API response. The _GenAiSystemProcessor copies gen_ai.provider.name to gen_ai.system and cloud.provider.
For full setup instructions, including how to configure the OpenTelemetry exporter for Beakpoint, see the Track LLM Costs guide.