Skip to content

Commit 4fa9c0a

Browse files
committed
llm analytics v1
1 parent 2e42913 commit 4fa9c0a

File tree

14 files changed

+881
-483
lines changed

14 files changed

+881
-483
lines changed

apps/api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@ai-sdk-tools/artifacts": "^1.2.0",
2121
"@ai-sdk-tools/memory": "^1.2.0",
2222
"@ai-sdk/openai": "^2.0.86",
23+
"@ai-sdk/provider": "^3.0.0",
2324
"@databuddy/auth": "workspace:*",
2425
"@databuddy/db": "workspace:*",
2526
"@databuddy/redis": "workspace:*",
@@ -38,11 +39,11 @@
3839
"@orpc/server": "^1.12.3",
3940
"ai": "^5.0.113",
4041
"autumn-js": "^0.1.48",
42+
"bullmq": "^5.34.0",
4143
"dayjs": "^1.11.19",
4244
"elysia": "^1.4.19",
4345
"jszip": "^3.10.1",
4446
"keypal": "^0.1.11",
45-
"bullmq": "^5.34.0",
4647
"zod": "catalog:"
4748
}
4849
}

apps/api/src/ai/config/models.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
12
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
23

34
const apiKey = process.env.AI_API_KEY;
@@ -12,6 +13,16 @@ export const openrouter = createOpenRouter({
1213
headers,
1314
});
1415

16+
// Create Databuddy LLM instance with transport
17+
const aiLogsApiUrl = process.env.AI_LOGS_API_URL;
18+
const { track } = databuddyLLM(
19+
aiLogsApiUrl
20+
? {
21+
apiUrl: aiLogsApiUrl,
22+
}
23+
: {}
24+
);
25+
1526
/**
1627
* Model configurations for different agent types.
1728
* Centralized here for easy switching and environment-based overrides.
@@ -21,27 +32,27 @@ export const openrouter = createOpenRouter({
2132
const overrideModel: string | null = null;
2233

2334
const modelNames = {
24-
triage: overrideModel || "anthropic/claude-haiku-4.5",
25-
analytics: overrideModel || "anthropic/claude-haiku-4.5",
35+
triage: overrideModel ?? "anthropic/claude-haiku-4.5",
36+
analytics: overrideModel ?? "anthropic/claude-haiku-4.5",
2637
// triage: "z-ai/glm-4.6",
2738
// analytics: "z-ai/glm-4.6",
28-
advanced: overrideModel || "anthropic/claude-sonnet-4.5",
39+
advanced: overrideModel ?? "anthropic/claude-sonnet-4.5",
2940
// advanced: "z-ai/glm-4.6",
3041
perplexity: "perplexity/sonar-pro",
3142
} as const;
3243

3344
export const models = {
3445
/** Fast, cheap model for routing/triage decisions */
35-
triage: openrouter.chat(modelNames.triage),
46+
triage: track(openrouter.chat(modelNames.triage)),
3647

3748
/** Balanced model for most analytical tasks */
38-
analytics: openrouter.chat(modelNames.analytics),
49+
analytics: track(openrouter.chat(modelNames.analytics)),
3950

4051
/** High-capability model for complex reasoning and reflection */
41-
advanced: openrouter.chat(modelNames.advanced),
52+
advanced: track(openrouter.chat(modelNames.advanced)),
4253

4354
/** Perplexity model for real-time web search and competitor analysis */
44-
perplexity: openrouter.chat(modelNames.perplexity),
55+
perplexity: track(openrouter.chat(modelNames.perplexity)),
4556
} as const;
4657

4758
export type ModelKey = keyof typeof models;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

apps/basket/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "./lib/tracing";
1212
import basketRouter from "./routes/basket";
1313
import emailRouter from "./routes/email";
14+
import llmRouter from "./routes/llm";
1415
import { closeGeoIPReader } from "./utils/ip-geo";
1516

1617
initTracing();
@@ -122,6 +123,7 @@ const app = new Elysia()
122123
.options("*", () => new Response(null, { status: 204 }))
123124
.use(basketRouter)
124125
.use(emailRouter)
126+
.use(llmRouter)
125127
.get("/health", function healthCheck() {
126128
return new Response(
127129
JSON.stringify({

0 commit comments

Comments
 (0)