Skip to main content
The Semantic Conventions define the keys and values which describe commonly observed concepts, protocols, and operations used by applications. These conventions are used to populate the attributes of spans and span events.

Span Kinds

The openinference.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_read represents the number of prompt tokens successfully retrieved from cache (cache hits). For OpenAI, this corresponds to the usage.prompt_tokens_details.cached_tokens field in completion API responses. For Anthropic, when using a cache_control block, this maps to the cache_read_input_tokens field in Messages API responses.
  • cache_write represents 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 the cache_write_input_tokens field in their Messages API responses.
The extended token count attributes follow the naming pattern:
  • llm.token_count.prompt_details.* for prompt-related token counts
  • llm.token_count.completion_details.* for completion-related token counts
These attributes enable:
  • 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

The llm.system attribute identifies the AI product/vendor, while llm.model_name contains the specific model identifier:
  • llm.system should use well-known values when applicable (e.g., “openai”, “anthropic”, “cohere”)
  • llm.model_name should contain the actual model name returned by the API (e.g., “gpt-4-0613”, “claude-3-opus-20240229”)
  • The llm.provider attribute can be used to identify the hosting provider when different from the system (e.g., “azure” for Azure-hosted OpenAI)
For embedding operations (openinference.span.kind: "EMBEDDING"):
  • llm.system and llm.provider are not used
  • Use embedding.model_name to 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:
Where:
  • <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 message
  • llm.output_messages.<index>.message.role - Role of the output message
  • llm.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 API
  • llm.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 item
  • llm.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 call
  • llm.output_messages.<messageIndex>.message.tool_calls.<toolCallIndex>.tool_call.function.name - Name of the function being called
  • llm.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]).