-
Notifications
You must be signed in to change notification settings - Fork 137
feat(semcov): Add Image Token Count and Cost Semantic Conventions #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@arizeai/openinference-semantic-conventions": major | ||
--- | ||
|
||
Add image semantic conventions |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,10 @@ export const LLM_TOKEN_COUNT_COMPLETION_DETAILS_REASONING = | |
export const LLM_TOKEN_COUNT_COMPLETION_DETAILS_AUDIO = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.token_count}.completion_details.audio` as const; | ||
|
||
/** Token count for image input generated by the model (in tokens) */ | ||
export const LLM_TOKEN_COUNT_COMPLETION_DETAILS_IMAGE = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.token_count}.completion_details.image` as const; | ||
|
||
/** Token count for the prompt to the llm (in tokens) */ | ||
export const LLM_TOKEN_COUNT_PROMPT = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.token_count}.prompt` as const; | ||
|
@@ -229,6 +233,10 @@ export const LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHE_READ = | |
export const LLM_TOKEN_COUNT_PROMPT_DETAILS_AUDIO = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.token_count}.prompt_details.audio` as const; | ||
|
||
/** Token count for image input presented in the prompt (in tokens) */ | ||
export const LLM_TOKEN_COUNT_PROMPT_DETAILS_IMAGE = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.token_count}.prompt_details.image` as const; | ||
|
||
/** Token count for the entire transaction with the llm (in tokens) */ | ||
export const LLM_TOKEN_COUNT_TOTAL = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.token_count}.total` as const; | ||
|
@@ -258,14 +266,16 @@ export const LLM_TOKEN_COUNT_COMPLETION_DETAILS = | |
* "completion_details": { | ||
* "output": 0.0009, # Cost in USD | ||
* "reasoning": 0.0024, # Cost in USD (e.g., 80 tokens * $0.03/1K tokens) | ||
* "audio": 0.0012 # Cost in USD (e.g., 40 tokens * $0.03/1K tokens) | ||
* "audio": 0.0012, # Cost in USD (e.g., 40 tokens * $0.03/1K tokens) | ||
* "image": 0.0018 # Cost in USD (e.g., 60 tokens * $0.03/1K tokens) | ||
* }, | ||
* "prompt_details": { | ||
* "input": 0.0003, # Cost in USD | ||
* "cache_write": 0.0006, # Cost in USD (e.g., 20 tokens * $0.03/1K tokens) | ||
* "cache_read": 0.0003, # Cost in USD (e.g., 10 tokens * $0.03/1K tokens) | ||
* "cache_input": 0.0006, # Cost in USD (e.g., 20 tokens * $0.03/1K tokens) | ||
* "audio": 0.0003 # Cost in USD (e.g., 10 tokens * $0.03/1K tokens) | ||
* "audio": 0.0003, # Cost in USD (e.g., 10 tokens * $0.03/1K tokens) | ||
* "image": 0.0009 # Cost in USD (e.g., 30 tokens * $0.03/1K tokens) | ||
* } | ||
* } | ||
* Note: This is a key prefix - individual attributes are stored as separate span attributes with this prefix, | ||
|
@@ -306,6 +316,10 @@ export const LLM_COST_COMPLETION_DETAILS_REASONING = | |
export const LLM_COST_COMPLETION_DETAILS_AUDIO = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.cost}.completion_details.audio` as const; | ||
|
||
/** Cost of image tokens in the completion in USD */ | ||
export const LLM_COST_COMPLETION_DETAILS_IMAGE = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.cost}.completion_details.image` as const; | ||
|
||
/** Cost of prompt tokens written to cache in USD */ | ||
export const LLM_COST_PROMPT_DETAILS_CACHE_WRITE = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.cost}.prompt_details.cache_write` as const; | ||
|
@@ -322,6 +336,10 @@ export const LLM_COST_PROMPT_DETAILS_CACHE_INPUT = | |
export const LLM_COST_PROMPT_DETAILS_AUDIO = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.cost}.prompt_details.audio` as const; | ||
|
||
/** Cost of image tokens in the prompt in USD */ | ||
export const LLM_COST_PROMPT_DETAILS_IMAGE = | ||
`${SemanticAttributePrefixes.llm}.${LLMAttributePostfixes.cost}.prompt_details.image` as const; | ||
|
||
/** | ||
* The role that the LLM assumes the message is from | ||
* during the LLM invocation | ||
|
@@ -638,11 +656,13 @@ export const SemanticConventions = { | |
LLM_TOKEN_COUNT_COMPLETION_DETAILS, | ||
LLM_TOKEN_COUNT_COMPLETION_DETAILS_REASONING, | ||
LLM_TOKEN_COUNT_COMPLETION_DETAILS_AUDIO, | ||
LLM_TOKEN_COUNT_COMPLETION_DETAILS_IMAGE, | ||
LLM_TOKEN_COUNT_PROMPT, | ||
LLM_TOKEN_COUNT_PROMPT_DETAILS, | ||
LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHE_WRITE, | ||
LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHE_READ, | ||
LLM_TOKEN_COUNT_PROMPT_DETAILS_AUDIO, | ||
LLM_TOKEN_COUNT_PROMPT_DETAILS_IMAGE, | ||
LLM_TOKEN_COUNT_TOTAL, | ||
LLM_SYSTEM, | ||
LLM_PROVIDER, | ||
|
@@ -655,10 +675,12 @@ export const SemanticConventions = { | |
LLM_COST_OUTPUT, | ||
LLM_COST_COMPLETION_DETAILS_REASONING, | ||
LLM_COST_COMPLETION_DETAILS_AUDIO, | ||
LLM_COST_COMPLETION_DETAILS_IMAGE, | ||
LLM_COST_PROMPT_DETAILS_CACHE_WRITE, | ||
LLM_COST_PROMPT_DETAILS_CACHE_READ, | ||
LLM_COST_PROMPT_DETAILS_CACHE_INPUT, | ||
LLM_COST_PROMPT_DETAILS_AUDIO, | ||
LLM_COST_PROMPT_DETAILS_IMAGE, | ||
MESSAGE_ROLE, | ||
MESSAGE_NAME, | ||
MESSAGE_TOOL_CALLS, | ||
|
@@ -747,4 +769,4 @@ export enum LLMProvider { | |
GOOGLE = "google", | ||
AWS = "aws", | ||
AZURE = "azure", | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is missing a trailing newline character at the end. Adding a newline at the end of files is standard practice for POSIX compliance and helps prevent issues with certain tools and version control systems. Consider adding a newline character to maintain consistency with standard file formatting conventions. Spotted by Diamond |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,10 @@ class SpanAttributes: | |
""" | ||
Number of tokens used for reasoning steps in the completion (in tokens). | ||
""" | ||
LLM_TOKEN_COUNT_COMPLETION_DETAILS_IMAGE = "llm.token_count.completion_details.image" | ||
""" | ||
The number of image tokens in the completion (in tokens). | ||
""" | ||
LLM_TOKEN_COUNT_PROMPT = "llm.token_count.prompt" | ||
""" | ||
Number of tokens in the prompt. | ||
|
@@ -108,6 +112,10 @@ class SpanAttributes: | |
""" | ||
Number of tokens in the prompt that were written to cache (in tokens). | ||
""" | ||
LLM_TOKEN_COUNT_PROMPT_DETAILS_IMAGE = "llm.token_count.prompt_details.image" | ||
""" | ||
The number of image tokens in the prompt (in tokens). | ||
""" | ||
LLM_TOKEN_COUNT_TOTAL = "llm.token_count.total" | ||
""" | ||
Total number of tokens, including both prompt and completion (in tokens). | ||
|
@@ -138,10 +146,37 @@ class SpanAttributes: | |
""" | ||
Cost of reasoning steps in the completion in USD. | ||
""" | ||
LLM_COST_PROMPT = "llm.cost.prompt" | ||
""" | ||
Total cost of all input tokens sent to the LLM in USD. This includes all tokens that were | ||
processed as part of the prompt, including system messages, user messages, and any other input. | ||
LLM_COST_COMPLETION_DETAILS_IMAGE = "llm.cost.completion_details.image" | ||
""" | ||
Cost of image tokens in the completion in USD. | ||
""" | ||
LLM_COST = "llm.cost" | ||
""" | ||
Key prefix for cost information. When these keys are transformed into a JSON-like structure, | ||
it would look like: | ||
{ | ||
"prompt": 0.0021, # Cost in USD | ||
"completion": 0.0045, # Cost in USD | ||
"total": 0.0066, # Cost in USD | ||
"input": 0.0003, # Cost in USD | ||
"output": 0.0009, # Cost in USD | ||
"completion_details": { | ||
"reasoning": 0.0024, # Cost in USD (e.g., 80 tokens * $0.03/1K tokens) | ||
"audio": 0.0012, # Cost in USD (e.g., 40 tokens * $0.03/1K tokens) | ||
"image": 0.0018 # Cost in USD (e.g., 60 tokens * $0.03/1K tokens) | ||
}, | ||
"prompt_details": { | ||
"cache_write": 0.0006, # Cost in USD (e.g., 20 tokens * $0.03/1K tokens) | ||
"cache_read": 0.0003, # Cost in USD (e.g., 10 tokens * $0.03/1K tokens) | ||
"cache_input": 0.0006, # Cost in USD (e.g., 20 tokens * $0.03/1K tokens) | ||
"audio": 0.0003, # Cost in USD (e.g., 10 tokens * $0.03/1K tokens) | ||
"image": 0.0009 # Cost in USD (e.g., 30 tokens * $0.03/1K tokens) | ||
} | ||
} | ||
Note: This is a key prefix - individual attributes are stored as separate span attributes | ||
with this prefix, e.g. llm.cost.prompt, llm.cost.completion_details.reasoning, etc. | ||
The JSON structure shown above represents how these separate attributes can be conceptually | ||
organized. All monetary values are in USD with floating point precision. | ||
""" | ||
LLM_COST_PROMPT_DETAILS = "llm.cost.prompt_details" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments here about |
||
""" | ||
|
@@ -171,6 +206,10 @@ class SpanAttributes: | |
input to the model, which may be different from the prompt cost if there are additional | ||
processing steps. | ||
""" | ||
LLM_COST_PROMPT_DETAILS_IMAGE = "llm.cost.prompt_details.image" | ||
""" | ||
Cost of image tokens in the prompt in USD. | ||
""" | ||
LLM_COST_TOTAL = "llm.cost.total" | ||
""" | ||
Total cost of the LLM call in USD (prompt + completion). | ||
|
Uh oh!
There was an error while loading. Please reload this page.