Skip to content

Commit

Permalink
feat: api-metrics (#49)
Browse files Browse the repository at this point in the history
* feat: api-metrics

* Update audio.ts

* Update name.ts

* Update text.ts

* Update vision.ts

---------

Co-authored-by: ben <[email protected]>
  • Loading branch information
aexshafii and benjaminshafii authored Apr 19, 2024
1 parent b249ff6 commit c19c7ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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: "call-api",
properties: { endpoint: "audio" },
});
}
if (error) {
console.error(error.message);
return res.status(500).json({ message: "Internal Server Error" });
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: "call-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: "call-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 c19c7ff

Please sign in to comment.