Documentation Index
Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Summary
Query and aggregate metrics across multiple Braintrust projects using the project_logs() function with multiple project IDs. Use estimated_cost() to compute costs directly in span-level queries across any number of projects.
Configuration Steps
Step 1: Query Multiple Projects Using Span Shape
Pass multiple project IDs to project_logs() and filter for LLM spans. Use estimated_cost() to aggregate costs without manual token math.
SELECT
date_trunc('day', ts) AS day,
metadata.model,
sum(estimated_cost()) AS total_cost,
sum(metrics.prompt_tokens) AS prompt_tokens,
sum(metrics.completion_tokens) AS completion_tokens,
sum(metrics.prompt_cached_tokens) AS cached_tokens
FROM project_logs('proj_id_1', 'proj_id_2', 'proj_id_3')
WHERE ts >= now() - interval '30 days'
AND span_attributes.type = 'llm'
GROUP BY 1, 2
ORDER BY 1;
Step 2: Alternative Approach Using Summary Shape
Query each project separately using summary shape and combine results in your application to use pre-calculated cost values.
-- Query each project individually
SELECT
date_trunc('day', ts) AS day,
sum(summary.estimated_cost) AS total_cost
FROM project_logs('proj_id_1') WITH (shape = 'summary')
WHERE ts >= now() - interval '30 days'
GROUP BY 1;
-- Repeat for each project, then combine client-side