Skip to content

Conversation

sallyannarize
Copy link
Contributor

@sallyannarize sallyannarize commented Jun 16, 2025

This PR adds support for image token counting and cost tracking across OpenInference semantic conventions.

Changes Made

New Semantic Conventions:

  • llm.token_count.prompt_details.image - Number of image tokens in the prompt
  • llm.token_count.completion_details.image - Number of image tokens in the completion
  • llm.cost.prompt_details.image - Cost of image tokens in the prompt (USD)
  • llm.cost.completion_details.image - Cost of image tokens in the completion (USD)

resolves #1780

Summary by Sourcery

Add image-specific token counting and cost tracking to OpenInference semantic conventions across Python and TypeScript implementations.

New Features:

  • Introduce llm.token_count.prompt_details.image and llm.token_count.completion_details.image to record image token counts.
  • Introduce llm.cost.prompt_details.image and llm.cost.completion_details.image to record image token costs.

Documentation:

  • Update semantic_conventions.md and TypeScript definitions to document new image-related attributes.

@sallyannarize sallyannarize marked this pull request as ready for review June 16, 2025 03:33
@sallyannarize sallyannarize requested review from a team as code owners June 16, 2025 03:33
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 16, 2025
Copy link

pkg-pr-new bot commented Jun 16, 2025

Open in StackBlitz

@arizeai/openinference-core

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-core@1787

@arizeai/openinference-instrumentation-beeai

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-beeai@1787

@arizeai/openinference-instrumentation-langchain

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-langchain@1787

@arizeai/openinference-instrumentation-mcp

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-mcp@1787

@arizeai/openinference-instrumentation-openai

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-instrumentation-openai@1787

@arizeai/openinference-mastra

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-mastra@1787

@arizeai/openinference-semantic-conventions

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-semantic-conventions@1787

@arizeai/openinference-vercel

npm i https://pkg.pr.new/Arize-ai/openinference/@arizeai/openinference-vercel@1787

commit: 08f6583

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sallyannarize - I've reviewed your changes - here's some feedback:

  • Remove the duplicated prompt_details and completion_details constant definitions in the Python SpanAttributes class to avoid redefinition conflicts and keep the attribute grouping consistent.
  • Consider splitting out the input/output cost prefix refactoring (LLM_COST_INPUT, LLM_COST_OUTPUT, etc.) into a separate PR so this one stays focused solely on adding the image token/count and cost conventions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Remove the duplicated prompt_details and completion_details constant definitions in the Python SpanAttributes class to avoid redefinition conflicts and keep the attribute grouping consistent.
- Consider splitting out the input/output cost prefix refactoring (LLM_COST_INPUT, LLM_COST_OUTPUT, etc.) into a separate PR so this one stays focused solely on adding the image token/count and cost conventions.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@caroger caroger moved this to In Review in Instrumentation Jun 17, 2025
@caroger caroger self-requested a review June 17, 2025 21:18
Total cost of all output tokens generated by the LLM in USD. This includes all tokens that were
generated in response to the prompt, including the main response and any additional output.
"""
LLM_COST_COMPLETION_DETAILS = "llm.cost.completion_details"
Copy link
Collaborator

@caroger caroger Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is removing or renaming LLM_COST_COMPLETION_DETAILS intentional?

if so, tests in test_attributes.py should be updated to reflect this change otherwise CI wouldn't pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must have accidentally deleted these, I have added them back

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_PROMPT_DETAILS = "llm.cost.prompt_details"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments here about LLM_COST_PROMPT_DETAILS

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 19, 2025
…ticConventions.ts

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
AWS = "aws",
AZURE = "azure",
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[semcov] image token counts
2 participants