langchain-ai / langsmith-sdk

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

Issue: Cost tracking for RunTree #848

Closed YassineRjl closed 1 month ago

YassineRjl commented 1 month ago

Issue you'd like to raise.

Hi there, I'm using RunTree and want to log the cost, I figured out how to add the token count but not the cost. Can someone guide me please?

PS: The provider openai and gpt-4 are just values to test with. I figured if it works for them it'll work for the other custom models I'm using like Command-R

Reference: https://docs.smith.langchain.com/how_to_guides/tracing/log_llm_trace#manually-provide-token-counts

   trace.end({
      data,
      usage_metadata: {
        input_tokens: 27,
        output_tokens: 13,
        total_tokens: 40,
        total_cost: ((inCost ?? 0) + (outCost ?? 0)),
        prompt_cost: inCost,
        completion_cost: outCost,
      },
      ls_provider: 'openai',
      ls_model_name: 'gpt-4',
    });

Suggestion:

No response

hinthornw commented 1 month ago

Hello! You're almost there! All that's remaining is to configure the model costs in the langsmith dashboard. The costs are estimated based on the matching model name

image