-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add operation.cost
span attribute to model request spans, rename ModelResponse.price()
to .cost()
#2767
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
Conversation
Docs Preview
|
operation.cost
span attribute to model request spans
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for tracking operation costs in OpenTelemetry spans by including an operation.cost
attribute when pricing information is available for AI model requests.
- Adds
operation.cost
span attribute to track the financial cost of AI model operations - Updates test fixtures to use realistic OpenAI models with known pricing (gpt-4o variants)
- Handles pricing lookup errors gracefully by omitting the cost attribute when pricing is unavailable
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
pydantic_ai_slim/pydantic_ai/models/instrumented.py | Adds cost tracking logic with error handling for pricing lookups |
tests/models/test_instrumented.py | Updates test model names and adds expected cost attributes to test assertions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
operation.cost
span attribute to model request spansoperation.cost
span attribute to model request spans, rename ModelResponse.price()
to .cost()
This gives the cost of a request in USD as calculated by genai-prices, if possible.
ModelResponse.price()
is now deprecated in favour ofModelResponse.cost()
which does the same thing.