Skip to content

Instantly share code, notes, and snippets.

@pedramamini
Created February 25, 2026 22:02
Show Gist options
  • Select an option

  • Save pedramamini/ddced802acdb4857bc3a172cfa564a87 to your computer and use it in GitHub Desktop.

Select an option

Save pedramamini/ddced802acdb4857bc3a172cfa564a87 to your computer and use it in GitHub Desktop.
Obsidian cost tracking code for RSSidian ingestions.
searchType: dvField,dvField,dvField              # all three come from inline fields
searchTarget: Ingestion_Date,Total_Tokens,Total_Cost
datasetName: Date,Tokens,Cost ($)
aspectRatio: 50:15
folder: "Content Farm/Web/Archive/2025"
dateFormat: YYYY-MM-DD
xDataset: 0                                       # 1st target drives the X-axis

line:
  yAxisLocation: none,left,right                 # hide the Date series itself
  lineColor: none,purple,green
  showLegend: true
  fillGap: true
  yMin: 0
const launchDate = new Date("2025-03-02");
const today = new Date();

// Calculate days since launch (inclusive of start date)
const daysSinceLaunch = Math.floor((today - launchDate) / (1000 * 60 * 60 * 24)) + 1;

const totalCost = dv.pages('"Content Farm/Web/Archive/2025"')
        .values
        .filter(p => p.Total_Cost)
        .reduce((sum, p) => sum + Number(p.Total_Cost), 0);

const totalTokens = dv.pages('"Content Farm/Web/Archive/2025"')
        .values
        .filter(p => p.Total_Tokens)
        .reduce((sum, p) => sum + Number(p.Total_Tokens), 0);

const costPerMillion = totalTokens > 0 
    ? (totalCost / totalTokens * 1_000_000).toFixed(2)
    : "N/A";

const avgCostPerDay = daysSinceLaunch > 0 
    ? (totalCost / daysSinceLaunch).toFixed(2)
    : "N/A";

dv.paragraph(`πŸ’° Total Running Cost (since 2025-03-02): **$${totalCost.toFixed(2)}**
πŸ“… Days Running: **${daysSinceLaunch}**
πŸ“ˆ Average Cost per Day: **$${avgCostPerDay}**
πŸͺ™ Total Token Count: **${totalTokens.toLocaleString()}**
πŸ“Š Cost per 1M Tokens: **$${costPerMillion}**`);
TABLE 
    (round(Total_Tokens / 1000)) AS "Total Tokens (1k)",
    "$" + (round(Total_Cost * 100) / 100) AS Total_Cost, 
    "$" + (round((Total_Cost / Total_Tokens * 1000000) * 100) / 100) AS "Cost per 1M Tokens"
FROM "Content Farm/Web/Archive"
WHERE Ingestion_Date AND startswith(file.folder, "Content Farm/Web/Archive/202")
SORT Ingestion_Date DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment