Skip to content

Permissions.Llm

Overview

Available Operations

  • grant - Grant permission to a user or make public
  • revoke - Revoke permission from a user or remove public access
  • check - Check user permission

grant

Grant a permission role to a user for a resource, or make the resource publicly accessible by using "*" as the userId. Only owners can grant permissions. Public access can be granted for writer and reader roles only. The authenticated user ID is extracted from the authentication header

Example Usage

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

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

async function run() {
  await sdk.permissions.llm.grant({
    resourceType: "completion",
    resourceId: "my-completion-123",
    userId: "user-abc456",
    role: "writer",
  });


}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { permissionsLlmGrant } from "@meetkai/mka1/funcs/permissionsLlmGrant.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 permissionsLlmGrant(sdk, {
    resourceType: "completion",
    resourceId: "my-completion-123",
    userId: "user-abc456",
    role: "writer",
  });
  if (res.ok) {
    const { value: result } = res;
    
  } else {
    console.log("permissionsLlmGrant 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 {
  // Mutation hook for triggering the API call.
  usePermissionsLlmGrantMutation
} from "@meetkai/mka1/react-query/permissionsLlmGrant.js";

Parameters

ParameterTypeRequiredDescription
requestcomponents.GrantPermissionRequest✔️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<void>

Errors

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

revoke

Revoke a permission role from a user for a resource, or remove public access by using "*" as the userId. Only owners can revoke permissions. The authenticated user ID is extracted from the authentication header

Example Usage

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

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

async function run() {
  await sdk.permissions.llm.revoke({
    resourceType: "completion",
    resourceId: "my-completion-123",
    userId: "user-abc456",
    role: "reader",
  });


}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { permissionsLlmRevoke } from "@meetkai/mka1/funcs/permissionsLlmRevoke.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 permissionsLlmRevoke(sdk, {
    resourceType: "completion",
    resourceId: "my-completion-123",
    userId: "user-abc456",
    role: "reader",
  });
  if (res.ok) {
    const { value: result } = res;
    
  } else {
    console.log("permissionsLlmRevoke 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 {
  // Mutation hook for triggering the API call.
  usePermissionsLlmRevokeMutation
} from "@meetkai/mka1/react-query/permissionsLlmRevoke.js";

Parameters

ParameterTypeRequiredDescription
requestcomponents.RevokePermissionRequest✔️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<void>

Errors

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

check

Check if the authenticated user has a specific permission on a resource. The user ID is extracted from the authentication header

Example Usage

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

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

async function run() {
  const result = await sdk.permissions.llm.check({
    resourceType: "vector_store",
    resourceId: "<id>",
    role: "writer",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { permissionsLlmCheck } from "@meetkai/mka1/funcs/permissionsLlmCheck.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 permissionsLlmCheck(sdk, {
    resourceType: "vector_store",
    resourceId: "<id>",
    role: "writer",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("permissionsLlmCheck 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.
  usePermissionsLlmCheck,
  usePermissionsLlmCheckSuspense,

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

Parameters

ParameterTypeRequiredDescription
requestoperations.LlmCheckRequest✔️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<components.CheckPermissionResponse>

Errors

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