diff --git a/app/pages/api/audio.ts b/app/pages/api/audio.ts index 4b612dbf..eb7fcb5f 100644 --- a/app/pages/api/audio.ts +++ b/app/pages/api/audio.ts @@ -6,6 +6,7 @@ import { tmpdir } from "os"; import { join } from "path"; import { promises as fsPromises } from "fs"; import { verifyKey } from "@unkey/api"; +import PosthogClient from "../../lib/posthog"; export const config = { api: { @@ -29,6 +30,16 @@ export default async function handler( const token = header.replace("Bearer ", ""); const { result, error } = await verifyKey(token); + + const client = PosthogClient(); + + if (client && result?.ownerId) { + client.capture({ + distinctId: result?.ownerId, + event: "call-api", + properties: { endpoint: "audio" }, + }); + } if (error) { console.error(error.message); return res.status(500).json({ message: "Internal Server Error" }); diff --git a/app/pages/api/text.ts b/app/pages/api/text.ts index 82701803..ed09a75a 100644 --- a/app/pages/api/text.ts +++ b/app/pages/api/text.ts @@ -1,6 +1,6 @@ import { verifyKey } from "@unkey/api"; import type { NextApiRequest, NextApiResponse } from "next"; - +import PosthogClient from "../../lib/posthog"; type ResponseData = { message: string; }; @@ -18,6 +18,18 @@ export default async function handler( const token = header.replace("Bearer ", ""); const { result, error } = await verifyKey(token); + + const client = PosthogClient(); + + if (client && result?.ownerId) { + client.capture({ + distinctId: result?.ownerId, + event: "call-api", + properties: { endpoint: "text" }, + }); + } + + if (error) { console.error(error.message); return res.status(500).json({ message: "Internal Server Error" }); diff --git a/app/pages/api/vision.ts b/app/pages/api/vision.ts index 9b031ca4..6208f2de 100644 --- a/app/pages/api/vision.ts +++ b/app/pages/api/vision.ts @@ -1,5 +1,6 @@ import { verifyKey } from "@unkey/api"; import type { NextApiRequest, NextApiResponse } from "next"; +import PosthogClient from "../../lib/posthog"; type ResponseData = { message: string; @@ -27,6 +28,15 @@ export default async function handler( const token = header.replace("Bearer ", ""); const { result, error } = await verifyKey(token); + const client = PosthogClient(); + + if (client && result?.ownerId) { + client.capture({ + distinctId: result?.ownerId, + event: "call-api", + properties: { endpoint: "vision" }, + }); + } if (error) { console.error(error.message); return res.status(500).json({ message: "Internal Server Error" });