Skip to content

MKA1 TypeScript SDK

Official TypeScript SDK for the MKA1 API.

Use @meetkai/mka1 to call MKA1 from Node.js, browsers, React apps, and agent tooling. The SDK includes typed clients for responses, agents, files, vector stores, evals, usage, model registry operations, guardrails, sandbox APIs, and more.

Full product and API documentation lives at docs.mka1.com.

Install

bash
npm add @meetkai/mka1
bash
pnpm add @meetkai/mka1
bash
bun add @meetkai/mka1
bash
yarn add @meetkai/mka1

The package ships both ESM and CommonJS builds. For supported runtimes, see RUNTIMES.md.

Quick Start

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

const mka1 = new SDK({
  bearerAuth: process.env.MKA1_API_KEY,
});

const models = await mka1.llm.models.list({});

console.log(models.data.map((model) => model.id));

Most write APIs use the same client:

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

const mka1 = new SDK({
  bearerAuth: process.env.MKA1_API_KEY,
});

const response = await mka1.llm.responses.create({
  responsesCreateRequest: {
    model: "<MODEL_ID>",
    input: "Summarize the latest MKA1 eval run.",
  },
});

console.log(response);

Authentication

Pass an MKA1 API key or bearer token when constructing the client:

typescript
const mka1 = new SDK({
  bearerAuth: process.env.MKA1_API_KEY,
});

You can also provide an async token resolver:

typescript
const mka1 = new SDK({
  bearerAuth: async () => refreshMka1Token(),
});

For account setup, API keys, and endpoint-specific examples, see docs.mka1.com.

Common Entry Points

typescript
mka1.llm.responses
mka1.llm.conversations
mka1.llm.files
mka1.llm.vectorStores
mka1.llm.evals
mka1.llm.models
mka1.llm.usage
mka1.agents
mka1.agentRuns
mka1.sandbox
mka1.permissions

The generated method reference below lists every resource and operation included in this SDK.

React Query

React hooks are available from @meetkai/mka1/react-query. Install the optional peer dependencies only if you plan to use those hooks:

bash
npm add @tanstack/react-query react react-dom

See REACT_QUERY.md for provider setup, suspense hooks, invalidation helpers, and mutation examples.

MCP Server

This package also exposes the MKA1 API as an installable Model Context Protocol server.

Node.js v20 or newer is required for the MCP server.

json
{
  "mcpServers": {
    "mka1": {
      "command": "npx",
      "args": [
        "-y",
        "--package",
        "@meetkai/mka1",
        "--",
        "mcp",
        "start",
        "--bearer-auth",
        "..."
      ]
    }
  }
}

For available server flags:

bash
npx -y --package @meetkai/mka1 -- mcp start --help

Available Resources and Operations

Available methods

AgentRuns

AgentSchedules

Agents

Auth.ApiKey

Guardrails

Llm.Batches

Llm.Chat

  • createChat - [Deprecated] Chat completions for OpenAI SDK/client usage ⚠️ Deprecated
  • stream - [Deprecated] Streaming chat completions for generated SDK usage ⚠️ Deprecated

Llm.Classify

  • classify - Classify text into predefined categories

Llm.Conversations

Llm.Embeddings

Llm.Evals

Llm.Extract

Llm.Feedback

Llm.Files

Llm.FineTuning

Llm.Images

  • create - Generate images from text descriptions

Llm.McpVault

Llm.MemoryStores

Llm.Models

Llm.Prompts

Llm.Responses

  • create - Create an agent-powered response with tool support
  • list - List all responses with pagination
  • get - Retrieve response by ID with status and results
  • update - Update a response
  • delete - Permanently delete a response and its data
  • cancel - Cancel an in-progress background response
  • wake - Wake a sleeping background response
  • listInputItems - List paginated input items for a response
  • compact - Compact a conversation

Llm.Skills

Llm.Speech

Llm.Usage

Llm.VectorStores

Permissions.Llm

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

Sandbox

SandboxUsage

Search.Graphrag

Search.Tables

Search.TextStore

Standalone functions

All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.

To read more about standalone functions, check FUNCTIONS.md.

Available standalone functions

React hooks with TanStack Query

React hooks built on TanStack Query are included in this SDK. These hooks and the utility functions provided alongside them can be used to build rich applications that pull data from the API using one of the most popular asynchronous state management library.

To learn about this feature and how to get started, check REACT_QUERY.md.

WARNING

This feature is currently in preview and is subject to breaking changes within the current major version of the SDK as we gather user feedback on it.

Available React hooks

Server-sent event streaming

Server-sent events are used to stream content from certain operations. These operations will expose the stream as an async iterable that can be consumed using a for await...of loop. The loop will terminate when the server no longer has any events to send and closes the underlying connection.

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

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

async function run() {
  const result = await sdk.llm.responses.create({
    responsesCreateRequest: {
      model: "meetkai:functionary-urdu-mini-pak",
      input: "What is the capital of France?",
    },
  });

  console.log(result);
}

run();

File uploads

Certain SDK methods accept files as part of a multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.

TIP

Depending on your JavaScript runtime, there are convenient utilities that return a handle to a file without reading the entire contents into memory:

  • Node.js v20+: Since v20, Node.js comes with a native openAsBlob function in node:fs.
  • Bun: The native Bun.file function produces a file handle that can be used for streaming file uploads.
  • Browsers: All supported browsers return an instance to a File when reading the value from an <input type="file"> element.
  • Node.js v18: A file stream can be created using the fileFrom helper from fetch-blob/from.js.
typescript
import { SDK } from "@meetkai/mka1";
import { openAsBlob } from "node:fs";

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

async function run() {
  const result = await sdk.llm.files.upload({
    requestBody: {
      file: await openAsBlob("example.file"),
      purpose: "assistants",
    },
  });

  console.log(result);
}

run();

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:

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

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

async function run() {
  await sdk.permissions.llm.grant({
    grantPermissionRequest: {
      resourceType: "completion",
      resourceId: "my-completion-123",
      userId: "user-abc456",
      role: "writer",
    },
  }, {
    retries: {
      strategy: "backoff",
      backoff: {
        initialInterval: 1,
        maxInterval: 50,
        exponent: 1.1,
        maxElapsedTime: 100,
      },
      retryConnectionErrors: false,
    },
  });
}

run();

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:

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

const sdk = new SDK({
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

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

run();

Error Handling

SDKError is the base class for all HTTP error responses. It has the following properties:

PropertyTypeDescription
error.messagestringError message
error.statusCodenumberHTTP response status code eg 404
error.headersHeadersHTTP response headers
error.bodystringHTTP body. Can be empty string if no body is returned.
error.rawResponseResponseRaw HTTP response
error.data$Optional. Some errors may contain structured data. See Error Classes.

Example

typescript
import { SDK } from "@meetkai/mka1";
import * as errors from "@meetkai/mka1/models/errors";

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

async function run() {
  try {
    const result = await sdk.llm.files.content({
      fileId: "file-abc123",
    });

    console.log(result);
  } catch (error) {
    // The base class for HTTP error responses
    if (error instanceof errors.SDKError) {
      console.log(error.message);
      console.log(error.statusCode);
      console.log(error.body);
      console.log(error.headers);

      // Depending on the method different errors may be thrown
      if (error instanceof errors.GetFileContentResponseBody) {
        console.log(error.data$.error); // errors.GetFileContentLlmFilesResponse400Error
      }
    }
  }
}

run();

Error Classes

Primary error:

  • SDKError: The base class for HTTP error responses.
Less common errors (20)

Network errors:

Inherit from SDKError:

* Check the method documentation to see if the error is applicable.

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the serverIdx: number optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

#ServerDescription
0https://apigw.mka1.comMKA1 API Gateway
1/Relative server URL (configurable via SDK constructor)

Example

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

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

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

run();

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:

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

const sdk = new SDK({
  serverURL: "https://apigw.mka1.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

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

run();

Custom HTTP Client

The TypeScript SDK makes API calls using an HTTPClient that wraps the native Fetch API. This client is a thin wrapper around fetch and provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle errors and response.

The HTTPClient constructor takes an optional fetcher argument that can be used to integrate a third-party HTTP client or when writing tests to mock out the HTTP client and feed in fixtures.

The following example shows how to:

  • route requests through a proxy server using undici's ProxyAgent
  • use the "beforeRequest" hook to add a custom header and a timeout to requests
  • use the "requestError" hook to log errors
typescript
import { SDK } from "@meetkai/mka1";
import { ProxyAgent } from "undici";
import { HTTPClient } from "@meetkai/mka1/lib/http";

const dispatcher = new ProxyAgent("http://proxy.example.com:8080");

const httpClient = new HTTPClient({
  // 'fetcher' takes a function that has the same signature as native 'fetch'.
  fetcher: (input, init) =>
    // 'dispatcher' is specific to undici and not part of the standard Fetch API.
    fetch(input, { ...init, dispatcher } as RequestInit),
});

httpClient.addHook("beforeRequest", (request) => {
  const nextRequest = new Request(request, {
    signal: request.signal || AbortSignal.timeout(5000)
  });

  nextRequest.headers.set("x-custom-header", "custom value");

  return nextRequest;
});

httpClient.addHook("requestError", (error, request) => {
  console.group("Request Error");
  console.log("Reason:", `${error}`);
  console.log("Endpoint:", `${request.method} ${request.url}`);
  console.groupEnd();
});

const sdk = new SDK({ httpClient: httpClient });

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches console's interface as an SDK option.

WARNING

Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.

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

const sdk = new SDK({ debugLogger: console });

Versioning

The SDK is generated from the MKA1 OpenAPI schema and may gain new endpoints frequently. Pin an exact package version when deploying production applications, then upgrade intentionally after reviewing the generated type changes.

Generated Code

Most files under src/, docs/, and the generated reference sections in this README are produced from the API schema. Changes to generated implementation files are likely to be overwritten by the next SDK generation. For API behavior questions, integration support, or documentation issues, use the support channels listed at docs.mka1.com.

Generated with Speakeasy.