Skip to content

Commit

Permalink
feat: api-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
aexshafii committed Apr 19, 2024
1 parent b249ff6 commit d8ce8a0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/pages/api/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: "audio-api",
properties: { endpoint: "audio" },
});
}
if (error) {
console.error(error.message);
return res.status(500).json({ message: "Internal Server Error" });
Expand Down
2 changes: 1 addition & 1 deletion app/pages/api/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async function handler(
if (client && result?.ownerId) {
client.capture({
distinctId: result?.ownerId,
event: "call-api",
event: "name-api",
properties: { endpoint: "name" },
});
}
Expand Down
14 changes: 13 additions & 1 deletion app/pages/api/text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { verifyKey } from "@unkey/api";
import type { NextApiRequest, NextApiResponse } from "next";

import PosthogClient from "../../lib/posthog";
type ResponseData = {
message: string;
};
Expand All @@ -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: "text-api",
properties: { endpoint: "text" },
});
}


if (error) {
console.error(error.message);
return res.status(500).json({ message: "Internal Server Error" });
Expand Down
10 changes: 10 additions & 0 deletions app/pages/api/vision.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { verifyKey } from "@unkey/api";
import type { NextApiRequest, NextApiResponse } from "next";
import PosthogClient from "../../lib/posthog";

type ResponseData = {
message: string;
Expand Down Expand Up @@ -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: "vision-api",
properties: { endpoint: "vision" },
});
}
if (error) {
console.error(error.message);
return res.status(500).json({ message: "Internal Server Error" });
Expand Down

0 comments on commit d8ce8a0

Please sign in to comment.