langchain-ai / langsmith-sdk

LangSmith Client SDK Implementations
https://smith.langchain.com/
MIT License
367 stars 65 forks source link

Issue: Custom cost tracking for langsmith calls #858

Open krrishdholakia opened 1 month ago

krrishdholakia commented 1 month ago

Issue you'd like to raise.

Hi, I'm trying to log custom cost to langsmith.

Here's my sample curl request: https://gist.github.com/krrishdholakia/434b1ef66decdb2e37b162537a615604

I'm following the format mentioned in docs: https://docs.smith.langchain.com/reference/data_formats/run_data_format

but i don't see the cost logged on UI

Screenshot 2024-07-09 at 9 16 10 AM

Suggestion:

No response

cc: @dqbd @hinthornw @eyurtsev

krrishdholakia commented 1 month ago

Observations:

when i look at the api swagger, total_cost isn't mentioned there - https://api.smith.langchain.com/redoc#tag/run/operation/create_run_api_v1_runs_post

this makes me think, this isn't actually supported by the langsmith api

hinthornw commented 1 month ago

Today, cost info is computed from the token counts. Token counts can be sent up on a runwise basis and then the costs are estimated based on the patterns you configure for your workspace.

image

krrishdholakia commented 1 month ago

hey @hinthornw i can see total_cost as a mentioned param on the api docs

Screenshot 2024-07-10 at 9 15 00 AM

https://docs.smith.langchain.com/reference/data_formats/run_data_format

is this not the case?

context - our users have custom cost for calls, and we need to log it accordingly

hinthornw commented 1 month ago

It's a computed value. It's present on the run resource as an aggregation of the tokens within child runs.

It's not a a field in the request body itself: https://api.smith.langchain.com/redoc#tag/run/operation/create_run_api_v1_runs_post