Skip to main content
LLM spans capture the API parameters sent to a LLM provider such as OpenAI or Cohere.

Required Attributes

All LLM spans MUST include:
  • openinference.span.kind: Set to "LLM"
  • llm.system: The AI system/product (e.g., “openai”, “anthropic”)

Common Attributes

LLM spans typically include:

Context Attributes

All LLM spans automatically inherit context attributes when they are set via the instrumentation context API. These attributes are propagated to every span in the trace without needing to be explicitly set on each span:
See Configuration for details on how to set these context attributes.

Attribute Flattening

While the examples below show attributes in a nested JSON format for readability, in actual OpenTelemetry spans, these attributes are flattened using indexed dot notation:
  • llm.input_messages.0.message.role instead of llm.input_messages[0].message.role
  • llm.output_messages.0.message.tool_calls.0.tool_call.function.name for nested tool calls
  • llm.tools.0.tool.json_schema for tool definitions

Tool Role Messages

When a message with message.role set to "tool" represents the result of a function call, the message.name attribute MAY be set to identify which function produced the result. This complements message.tool_call_id, which links the result back to the original tool call request. For example:
See Tool Calling for the complete tool calling flow.

Examples

Chat Completions

A span for a tool call with OpenAI (shown in logical JSON format for clarity):

Synthesis Call Using Function Output

A synthesis call using a function call output:

Completions

A span for a simple completion (shown in logical JSON format for clarity):