How to fetch the output and input tokens of a trace via API? #3902
-
|
Can I do that via API without a trace id? I can only get the total tokens by langfuse.fetch_traces(). |
Beta Was this translation helpful? Give feedback.
Answered by
dosubot[bot]
Oct 24, 2024
Replies: 1 comment 7 replies
-
|
To fetch detailed trace information, including input and output tokens, you can use the following API endpoints provided by Langfuse:
If you're using the Langfuse Python SDK, you can log input and output tokens using the langfuse_context.update_current_observation(
usage={
"input": response.usage.input_tokens,
"output": response.usage.output_tokens
}
)This method captures and logs the input and output tokens of a trace [2]. |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
marcklingen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To fetch detailed trace information, including input and output tokens, you can use the following API endpoints provided by Langfuse:
GET /api/public/traces: This endpoint allows you to fetch a list of traces.GET /api/public/traces/:traceId: This endpoint allows you to fetch a single trace by its ID, which may include detailed information such as input and output tokens [1].If you're using the Langfuse Python SDK, you can log input and output tokens using the
langfuse_context.update_current_observationmethod. Here's an example:T…