attributes of spans and span events.
Span Kinds
Theopeninference.span.kind attribute is required for all OpenInference spans and identifies the type of operation being traced. The span kind provides a hint to the tracing backend as to how the trace should be assembled. Valid values include:
Reserved Attributes
The following attributes are reserved and MUST be supported by all OpenInference Tracing SDKs:List-valued attributes (marked with †) use zero-based indexing in their flattened form. All list-based attributes are flattened using indexed prefixes (e.g.,
llm.input_messages.0.message.role).Well-Known Values
LLM System
llm.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.
LLM Provider
llm.provider has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.
Token Count Details
llm.token_count.prompt_details.cache_read and llm.token_count.prompt_details.cache_write provide granular token count information for cache operations, enabling detailed API usage tracking and cost analysis.
cache_readrepresents the number of prompt tokens successfully retrieved from cache (cache hits). For OpenAI, this corresponds to theusage.prompt_tokens_details.cached_tokensfield in completion API responses. For Anthropic, when using a cache_control block, this maps to thecache_read_input_tokensfield in Messages API responses.cache_writerepresents the number of prompt tokens not found in cache (cache misses) that were subsequently written to cache. This metric is specific to Anthropic and corresponds to thecache_write_input_tokensfield in their Messages API responses.
llm.token_count.prompt_details.*for prompt-related token countsllm.token_count.completion_details.*for completion-related token counts
- Tracking of multimodal token usage (audio tokens)
- Monitoring reasoning token consumption for models with chain-of-thought capabilities
- Cache efficiency analysis for cost optimization
- Detailed billing reconciliation
All token count attributes store integer values representing the count of tokens. Cost attributes store floating point values in USD currency.
System and Model Identification
Thellm.system attribute identifies the AI product/vendor, while llm.model_name contains the specific model identifier:
llm.systemshould use well-known values when applicable (e.g., “openai”, “anthropic”, “cohere”)llm.model_nameshould contain the actual model name returned by the API (e.g., “gpt-4-0613”, “claude-3-opus-20240229”)- The
llm.providerattribute can be used to identify the hosting provider when different from the system (e.g., “azure” for Azure-hosted OpenAI)
openinference.span.kind: "EMBEDDING"):
llm.systemandllm.providerare not used- Use
embedding.model_nameto identify the embedding model (e.g., “text-embedding-3-small”, “text-embedding-ada-002”) - See the Embedding Spans specification for the rationale
Attribute Naming Conventions
Indexed Attribute Prefixes
When dealing with lists of structured data, OpenInference uses indexed prefixes to create flattened attribute names. The general pattern is:<prefix>is the base attribute name (e.g.,llm.input_messages,llm.tools)<index>is a zero-based integer index<suffix>is the nested attribute path
Common Flattened Attribute Patterns
LLM Input/Output Messages
llm.input_messages.<index>.message.role- Role of the message (e.g., “user”, “assistant”, “system”)llm.input_messages.<index>.message.content- Text content of the messagellm.output_messages.<index>.message.role- Role of the output messagellm.output_messages.<index>.message.content- Text content of the output message
Completions API (Legacy Text Completion)
For the legacy completions API (non-chat):llm.prompts.<index>.prompt.text- Input prompt(s) provided to the completions APIllm.choices.<index>.completion.text- Text choice(s) returned from the completions API
Message Content Arrays (Multimodal)
For messages containing multiple content items (text, images, audio):llm.input_messages.<messageIndex>.message.contents.<contentIndex>.message_content.text- Text content itemllm.input_messages.<messageIndex>.message.contents.<contentIndex>.message_content.type- Content type (“text”, “image”, “audio”)llm.input_messages.<messageIndex>.message.contents.<contentIndex>.message_content.image.image.url- Image URL or base64 data
Tool Calls in Output Messages
llm.output_messages.<messageIndex>.message.tool_calls.<toolCallIndex>.tool_call.id- Unique identifier for the tool callllm.output_messages.<messageIndex>.message.tool_calls.<toolCallIndex>.tool_call.function.name- Name of the function being calledllm.output_messages.<messageIndex>.message.tool_calls.<toolCallIndex>.tool_call.function.arguments- JSON string of function arguments
Available Tools
llm.tools.<index>.tool.json_schema- Complete JSON schema of the tool
Implementation Examples
If the objects are further nested, flattening should continue until the attribute values are either simple values (bool, str, bytes, int, float) or simple lists (List[bool], List[str], List[bytes], List[int], List[float]).