How to Include Token Usage and Cost Details in LangServe Response JSON? #806
Unanswered
quartermaine
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a LangServe implementation and would like to enhance the response JSON to include metadata related to token usage and cost details for a chain. Specifically, I want to track the following metrics:
Total Tokens
Prompt Tokens
Completion Tokens
Total Cost (USD)
For context, here’s an example of my current chain setup:
I’d like to integrate these metrics into the response_metadata of the JSON returned by the chain.
In my previous standalone scripts using OpenAI’s API, I’ve used the get_openai_callback() context manager to extract these details, as shown below:
However, I’m not sure how to incorporate similar logic into my LangServe chain and ensure that these details are added to the response JSON.
Beta Was this translation helpful? Give feedback.
All reactions