Files
avz-site/api/kimi/platform.ts
T
2026-06-08 23:50:59 -03:00

31 lines
712 B
TypeScript

import { env } from "../lib/env";
import type { UserProfile } from "./types";
async function kimiRequest<T>(
path: string,
token: string,
init?: RequestInit,
): Promise<T | null> {
const resp = await fetch(`${env.kimiOpenUrl}${path}`, {
...init,
headers: {
Accept: "application/json",
Authorization: `Bearer ${token}`,
...init?.headers,
},
});
if (!resp.ok) {
const text = await resp.text();
console.warn(
`[kimi] Request to ${path} failed (${resp.status}): ${text}`,
);
return null;
}
return resp.json() as Promise<T>;
}
export const users = {
getProfile: (token: string) =>
kimiRequest<UserProfile>("/v1/users/me/profile", token),
};