Efficient Token Breakdown by Model in a Specific Session
Hello 馃檪 What would be the most efficient way to get token breakdown (completion, prompt, total, reasoning) by model for a specific session? Currently, I'm doing:
df = px.Client().get_spans_dataframe('session.id == "my-session-id"', project_name="my-project", limit=10000, timeout=30)and then:
def get_token_breakdown(df):
return (
df.groupby("attributes.llm.model_name")
.agg(
{
"attributes.llm.token_count.total": "sum",
"attributes.llm.token_count.prompt": "sum",
"attributes.llm.token_count.completion": "sum",
"attributes.llm.token_count.completion_details.reasoning": "sum",
}
)
.rename(
columns={
"attributes.llm.token_count.total": "total",
"attributes.llm.token_count.prompt": "prompt",
"attributes.llm.token_count.completion": "completion",
"attributes.llm.token_count.completion_details.reasoning": "reasoning",
}
)
.transpose()
.to_dict()
)and 30 seconds timeout is definitely needed here. Is there a more performant way? Thanks! 馃檹
