Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions apps/code/src/renderer/api/posthogClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { SpendAnalysisResponse } from "@features/billing/types/spend-analysis";
import { isSupportedReasoningEffort } from "@posthog/agent/adapters/reasoning-effort";
import type { PermissionMode } from "@posthog/agent/execution-mode";
import {
Expand Down Expand Up @@ -2855,4 +2856,35 @@ export class PostHogAPIClient {
const blob = await response.blob();
return URL.createObjectURL(blob);
}

/**
* Fetch the requesting user's personal LLM spend analysis. `dateFrom` / `dateTo`
* accept absolute dates (`2026-04-23`) or relative strings (`-7d`, `-1m`), and
* default to the last 30 days. When `product` is set the tool / model / trace
* breakdowns are scoped to that `ai_product` (e.g. `posthog_code`); when omitted
* they aggregate across every product.
*/
async getPersonalSpendAnalysis(
options: { dateFrom?: string; dateTo?: string; product?: string } = {},
): Promise<SpendAnalysisResponse> {
const { dateFrom = "-30d", dateTo, product } = options;
const urlPath = `/api/llm_analytics/@me/spend/`;
const url = new URL(`${this.api.baseUrl}${urlPath}`);
url.searchParams.set("date_from", dateFrom);
if (dateTo) {
url.searchParams.set("date_to", dateTo);
}
if (product) {
url.searchParams.set("product", product);
}
const response = await this.api.fetcher.fetch({
method: "get",
url,
path: urlPath,
});
if (!response.ok) {
throw new Error(`Failed to fetch spend analysis: ${response.status}`);
}
return (await response.json()) as SpendAnalysisResponse;
}
}
Loading
Loading