Llm.Embeddings
Overview
Available Operations
- listModels - List available embedding models
- embed - Create text embeddings
listModels
Returns a list of available embedding models with their limits. Use this endpoint to discover which models are available and their constraints (batch size, input length) before making embedding requests.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.embeddings.listModels();
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmEmbeddingsListModels } from "@meetkai/mka1/funcs/llmEmbeddingsListModels.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 llmEmbeddingsListModels(sdk);
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmEmbeddingsListModels 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.
import {
// Query hooks for fetching data.
useLlmEmbeddingsListModels,
useLlmEmbeddingsListModelsSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchLlmEmbeddingsListModels,
// Utility to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateAllLlmEmbeddingsListModels,
} from "@meetkai/mka1/react-query/llmEmbeddingsListModels.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.EmbeddingModelListResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |
embed
Generate vector embeddings for single or multiple text inputs using various embedding models. Embeddings convert text into numerical vectors that capture semantic meaning, enabling similarity search, clustering, and other vector-based operations. Supports batch processing with model-specific limits. Use GET /embeddings/models to discover available models and their limits. Returns floating-point vectors along with token usage statistics for cost tracking and optimization.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.embeddings.embed({
input: "The quick brown fox jumps over the lazy dog.",
model: "openai:text-embedding-3-small",
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmEmbeddingsEmbed } from "@meetkai/mka1/funcs/llmEmbeddingsEmbed.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 llmEmbeddingsEmbed(sdk, {
input: "The quick brown fox jumps over the lazy dog.",
model: "openai:text-embedding-3-small",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmEmbeddingsEmbed 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.
import {
// Mutation hook for triggering the API call.
useLlmEmbeddingsEmbedMutation
} from "@meetkai/mka1/react-query/llmEmbeddingsEmbed.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | components.EmbeddingsRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.EmbeddingsResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |