Skip to content

Usage

(llm.usage)

Overview

Available Operations

getUserUsageStats

Retrieve detailed usage analytics for a specific user including total token consumption, request counts, per-model breakdowns, and daily usage trends. Returns aggregate statistics across all requests, per-model usage showing which models were used and how much, and daily time-series data for tracking usage over time. Optionally filter by date range using ISO 8601 formatted startDate and endDate query parameters. Perfect for building usage dashboards, cost analysis, quota monitoring, and user activity reports. Token counts include both prompt and completion tokens for accurate cost calculation.

Example Usage

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.llm.usage.getUserUsageStats({
    userId: "<id>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmUsageGetUserUsageStats } from "@meetkai/mka1/funcs/llmUsageGetUserUsageStats.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await llmUsageGetUserUsageStats(sdk, {
    userId: "<id>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("llmUsageGetUserUsageStats failed:", res.error);
  }
}

run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

tsx
import {
  // Query hooks for fetching data.
  useLlmUsageGetUserUsageStats,
  useLlmUsageGetUserUsageStatsSuspense,

  // Utility for prefetching data during server-side rendering and in React
  // Server Components that will be immediately available to client components
  // using the hooks.
  prefetchLlmUsageGetUserUsageStats,
  
  // Utilities to invalidate the query cache for this query in response to
  // mutations and other user actions.
  invalidateLlmUsageGetUserUsageStats,
  invalidateAllLlmUsageGetUserUsageStats,
} from "@meetkai/mka1/react-query/llmUsageGetUserUsageStats.js";

Parameters

ParameterTypeRequiredDescription
requestoperations.GetUserUsageStatsRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.GetUserUsageStatsResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

listUserChatCompletions

Retrieve a paginated list of all chat completions for a specific user, ordered by most recent first. Each completion includes the request ID, model used, token consumption details, finish reason, streaming status, the original messages, and any associated user feedback. Supports pagination with customizable page size (1-200 items, default 50). Returns pagination metadata including total count and pages. Use this to build user history views, audit logs, or analyze individual user behavior patterns and model preferences.

Example Usage

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.llm.usage.listUserChatCompletions({
    userId: "<id>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmUsageListUserChatCompletions } from "@meetkai/mka1/funcs/llmUsageListUserChatCompletions.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await llmUsageListUserChatCompletions(sdk, {
    userId: "<id>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("llmUsageListUserChatCompletions failed:", res.error);
  }
}

run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

tsx
import {
  // Query hooks for fetching data.
  useLlmUsageListUserChatCompletions,
  useLlmUsageListUserChatCompletionsSuspense,

  // Utility for prefetching data during server-side rendering and in React
  // Server Components that will be immediately available to client components
  // using the hooks.
  prefetchLlmUsageListUserChatCompletions,
  
  // Utilities to invalidate the query cache for this query in response to
  // mutations and other user actions.
  invalidateLlmUsageListUserChatCompletions,
  invalidateAllLlmUsageListUserChatCompletions,
} from "@meetkai/mka1/react-query/llmUsageListUserChatCompletions.js";

Parameters

ParameterTypeRequiredDescription
requestoperations.ListUserChatCompletionsRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ListUserChatCompletionsResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

getChatCompletionByRequestId

Retrieve detailed information about a specific chat completion using its unique request ID (chatcmpl-xxx format). Returns complete details including the model used, full message history, token usage breakdown (prompt, completion, and total tokens), finish reason indicating why generation stopped, whether it was a streaming request, and any user feedback ratings or comments. Useful for debugging, auditing individual requests, displaying request history details, or correlating completions with external systems using the request ID.

Example Usage

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.llm.usage.getChatCompletionByRequestId({
    requestId: "<id>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmUsageGetChatCompletionByRequestId } from "@meetkai/mka1/funcs/llmUsageGetChatCompletionByRequestId.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await llmUsageGetChatCompletionByRequestId(sdk, {
    requestId: "<id>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("llmUsageGetChatCompletionByRequestId failed:", res.error);
  }
}

run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

tsx
import {
  // Query hooks for fetching data.
  useLlmUsageGetChatCompletionByRequestId,
  useLlmUsageGetChatCompletionByRequestIdSuspense,

  // Utility for prefetching data during server-side rendering and in React
  // Server Components that will be immediately available to client components
  // using the hooks.
  prefetchLlmUsageGetChatCompletionByRequestId,
  
  // Utilities to invalidate the query cache for this query in response to
  // mutations and other user actions.
  invalidateLlmUsageGetChatCompletionByRequestId,
  invalidateAllLlmUsageGetChatCompletionByRequestId,
} from "@meetkai/mka1/react-query/llmUsageGetChatCompletionByRequestId.js";

Parameters

ParameterTypeRequiredDescription
requestoperations.GetChatCompletionByRequestIdRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.GetChatCompletionByRequestIdResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*