-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Adding usage info in llm.py #4172
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
Merged
lorenzejay
merged 15 commits into
crewAIInc:main
from
Vidit-Ostwal:vo/fix/add-usage-metrics
Jan 7, 2026
+715
−10
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3135ae6
Adding usage info everywhere
Vidit-Ostwal 8ca96cb
Changing the check
Vidit-Ostwal 4fce98e
Changing the logic
Vidit-Ostwal 41d3908
Adding tests
Vidit-Ostwal b33723f
Adding casellets
Vidit-Ostwal 3dc3193
Minor change
Vidit-Ostwal 2fa62f0
Fixing testcase
Vidit-Ostwal b24017c
remove the duplicated test case, thanks to cursor
Vidit-Ostwal 9969c13
Merge branch 'main' into vo/fix/add-usage-metrics
Vidit-Ostwal 0640c1b
Merge branch 'main' into vo/fix/add-usage-metrics
Vidit-Ostwal 14f51f1
Merge branch 'main' into vo/fix/add-usage-metrics
Vidit-Ostwal 8816555
Adding async test cases
Vidit-Ostwal 605d533
Merge branch 'main' into vo/fix/add-usage-metrics
Vidit-Ostwal 15e8d58
Updating test case
Vidit-Ostwal 104075a
Merge branch 'main' into vo/fix/add-usage-metrics
lorenzejay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
lib/crewai/tests/cassettes/test_usage_info_non_streaming_with_acall.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| interactions: | ||
| - request: | ||
| body: '{"messages":[{"role":"user","content":"Tell me a joke."}],"model":"gpt-4o-mini","stop":[]}' | ||
| headers: | ||
| User-Agent: | ||
| - X-USER-AGENT-XXX | ||
| accept: | ||
| - application/json | ||
| accept-encoding: | ||
| - ACCEPT-ENCODING-XXX | ||
| authorization: | ||
| - AUTHORIZATION-XXX | ||
| connection: | ||
| - keep-alive | ||
| content-length: | ||
| - '90' | ||
| content-type: | ||
| - application/json | ||
| host: | ||
| - api.openai.com | ||
| x-stainless-arch: | ||
| - X-STAINLESS-ARCH-XXX | ||
| x-stainless-async: | ||
| - async:asyncio | ||
| x-stainless-lang: | ||
| - python | ||
| x-stainless-os: | ||
| - X-STAINLESS-OS-XXX | ||
| x-stainless-package-version: | ||
| - 2.14.0 | ||
| x-stainless-raw-response: | ||
| - 'true' | ||
| x-stainless-read-timeout: | ||
| - X-STAINLESS-READ-TIMEOUT-XXX | ||
| x-stainless-retry-count: | ||
| - '0' | ||
| x-stainless-runtime: | ||
| - CPython | ||
| x-stainless-runtime-version: | ||
| - 3.11.14 | ||
| method: POST | ||
| uri: https://api.openai.com/v1/chat/completions | ||
| response: | ||
| body: | ||
| string: "{\n \"id\": \"chatcmpl-CvErx9mbnUKFHKkhPChO93eUzKJqy\",\n \"object\": | ||
| \"chat.completion\",\n \"created\": 1767757889,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n | ||
| \ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": | ||
| \"assistant\",\n \"content\": \"Why did the scarecrow win an award? | ||
| \\n\\nBecause he was outstanding in his field!\",\n \"refusal\": null,\n | ||
| \ \"annotations\": []\n },\n \"logprobs\": null,\n \"finish_reason\": | ||
| \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 12,\n \"completion_tokens\": | ||
| 18,\n \"total_tokens\": 30,\n \"prompt_tokens_details\": {\n \"cached_tokens\": | ||
| 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": | ||
| {\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\": | ||
| 0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\": | ||
| \"default\",\n \"system_fingerprint\": \"fp_29330a9688\"\n}\n" | ||
| headers: | ||
| Access-Control-Expose-Headers: | ||
| - ACCESS-CONTROL-XXX | ||
| CF-RAY: | ||
| - CF-RAY-XXX | ||
| Connection: | ||
| - keep-alive | ||
| Content-Type: | ||
| - application/json | ||
| Date: | ||
| - Wed, 07 Jan 2026 03:51:29 GMT | ||
| Server: | ||
| - cloudflare | ||
| Set-Cookie: | ||
| - SET-COOKIE-XXX | ||
| Strict-Transport-Security: | ||
| - STS-XXX | ||
| Transfer-Encoding: | ||
| - chunked | ||
| X-Content-Type-Options: | ||
| - X-CONTENT-TYPE-XXX | ||
| alt-svc: | ||
| - h3=":443"; ma=86400 | ||
| cf-cache-status: | ||
| - DYNAMIC | ||
| content-length: | ||
| - '887' | ||
| openai-organization: | ||
| - OPENAI-ORG-XXX | ||
| openai-processing-ms: | ||
| - '466' | ||
| openai-project: | ||
| - OPENAI-PROJECT-XXX | ||
| openai-version: | ||
| - '2020-10-01' | ||
| x-envoy-upstream-service-time: | ||
| - '483' | ||
| x-openai-proxy-wasm: | ||
| - v0.1 | ||
| x-ratelimit-limit-requests: | ||
| - X-RATELIMIT-LIMIT-REQUESTS-XXX | ||
| x-ratelimit-limit-tokens: | ||
| - X-RATELIMIT-LIMIT-TOKENS-XXX | ||
| x-ratelimit-remaining-requests: | ||
| - X-RATELIMIT-REMAINING-REQUESTS-XXX | ||
| x-ratelimit-remaining-tokens: | ||
| - X-RATELIMIT-REMAINING-TOKENS-XXX | ||
| x-ratelimit-reset-requests: | ||
| - X-RATELIMIT-RESET-REQUESTS-XXX | ||
| x-ratelimit-reset-tokens: | ||
| - X-RATELIMIT-RESET-TOKENS-XXX | ||
| x-request-id: | ||
| - X-REQUEST-ID-XXX | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
113 changes: 113 additions & 0 deletions
113
lib/crewai/tests/cassettes/test_usage_info_non_streaming_with_call.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| interactions: | ||
| - request: | ||
| body: '{"messages":[{"role":"user","content":"Tell me a joke."}],"model":"gpt-4o-mini","stop":[]}' | ||
| headers: | ||
| User-Agent: | ||
| - X-USER-AGENT-XXX | ||
| accept: | ||
| - application/json | ||
| accept-encoding: | ||
| - ACCEPT-ENCODING-XXX | ||
| authorization: | ||
| - AUTHORIZATION-XXX | ||
| connection: | ||
| - keep-alive | ||
| content-length: | ||
| - '90' | ||
| content-type: | ||
| - application/json | ||
| host: | ||
| - api.openai.com | ||
| x-stainless-arch: | ||
| - X-STAINLESS-ARCH-XXX | ||
| x-stainless-async: | ||
| - 'false' | ||
| x-stainless-lang: | ||
| - python | ||
| x-stainless-os: | ||
| - X-STAINLESS-OS-XXX | ||
| x-stainless-package-version: | ||
| - 2.14.0 | ||
| x-stainless-raw-response: | ||
| - 'true' | ||
| x-stainless-read-timeout: | ||
| - X-STAINLESS-READ-TIMEOUT-XXX | ||
| x-stainless-retry-count: | ||
| - '0' | ||
| x-stainless-runtime: | ||
| - CPython | ||
| x-stainless-runtime-version: | ||
| - 3.11.14 | ||
| method: POST | ||
| uri: https://api.openai.com/v1/chat/completions | ||
| response: | ||
| body: | ||
| string: "{\n \"id\": \"chatcmpl-CugAsv9iAHdiGddGDHcZWEp7ZV7cB\",\n \"object\": | ||
| \"chat.completion\",\n \"created\": 1767624522,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n | ||
| \ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": | ||
| \"assistant\",\n \"content\": \"Why don't skeletons fight each other? | ||
| \\n\\nThey don't have the guts!\",\n \"refusal\": null,\n \"annotations\": | ||
| []\n },\n \"logprobs\": null,\n \"finish_reason\": \"stop\"\n | ||
| \ }\n ],\n \"usage\": {\n \"prompt_tokens\": 12,\n \"completion_tokens\": | ||
| 15,\n \"total_tokens\": 27,\n \"prompt_tokens_details\": {\n \"cached_tokens\": | ||
| 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\": | ||
| {\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\": | ||
| 0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\": | ||
| \"default\",\n \"system_fingerprint\": \"fp_29330a9688\"\n}\n" | ||
| headers: | ||
| CF-RAY: | ||
| - CF-RAY-XXX | ||
| Connection: | ||
| - keep-alive | ||
| Content-Type: | ||
| - application/json | ||
| Date: | ||
| - Mon, 05 Jan 2026 14:48:43 GMT | ||
| Server: | ||
| - cloudflare | ||
| Set-Cookie: | ||
| - SET-COOKIE-XXX | ||
| Strict-Transport-Security: | ||
| - STS-XXX | ||
| Transfer-Encoding: | ||
| - chunked | ||
| X-Content-Type-Options: | ||
| - X-CONTENT-TYPE-XXX | ||
| access-control-expose-headers: | ||
| - ACCESS-CONTROL-XXX | ||
| alt-svc: | ||
| - h3=":443"; ma=86400 | ||
| cf-cache-status: | ||
| - DYNAMIC | ||
| content-length: | ||
| - '874' | ||
| openai-organization: | ||
| - OPENAI-ORG-XXX | ||
| openai-processing-ms: | ||
| - '424' | ||
| openai-project: | ||
| - OPENAI-PROJECT-XXX | ||
| openai-version: | ||
| - '2020-10-01' | ||
| x-envoy-upstream-service-time: | ||
| - '1017' | ||
| x-openai-proxy-wasm: | ||
| - v0.1 | ||
| x-ratelimit-limit-requests: | ||
| - X-RATELIMIT-LIMIT-REQUESTS-XXX | ||
| x-ratelimit-limit-tokens: | ||
| - X-RATELIMIT-LIMIT-TOKENS-XXX | ||
| x-ratelimit-remaining-requests: | ||
| - X-RATELIMIT-REMAINING-REQUESTS-XXX | ||
| x-ratelimit-remaining-tokens: | ||
| - X-RATELIMIT-REMAINING-TOKENS-XXX | ||
| x-ratelimit-reset-requests: | ||
| - X-RATELIMIT-RESET-REQUESTS-XXX | ||
| x-ratelimit-reset-tokens: | ||
| - X-RATELIMIT-RESET-TOKENS-XXX | ||
| x-request-id: | ||
| - X-REQUEST-ID-XXX | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.