Skip to main content
Glama

create_embeddings

Generate embeddings for text using the Grok API, specifying model, input, encoding format, and dimensions for accurate vector representations.

Instructions

Create embeddings for text with the Grok API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dimensionsNoThe number of dimensions the resulting output embeddings should have
encoding_formatNoThe format to return the embeddings in
inputYesInput text to get embeddings for
modelYesID of the model to use
userNoA unique user identifier

Implementation Reference

  • Core handler function implementing the embedding creation logic by making a POST request to the Grok embeddings endpoint and parsing the response.
    export async function createEmbeddings( options: z.infer<typeof EmbeddingsRequestSchema> ): Promise<z.infer<typeof EmbeddingsResponseSchema>> { const response = await grokRequest("embeddings", { method: "POST", body: options, }); return EmbeddingsResponseSchema.parse(response); }
  • Zod schema defining the input parameters for the create_embeddings tool.
    export const EmbeddingsRequestSchema = z.object({ model: z.string().describe("ID of the model to use"), input: z .union([ z.string(), z.array(z.string()), z.array(z.number()), z.array(z.array(z.number())), ]) .describe("Input text to get embeddings for"), encoding_format: z .enum(["float", "base64"]) .optional() .describe("The format to return the embeddings in"), dimensions: z .number() .int() .positive() .optional() .describe( "The number of dimensions the resulting output embeddings should have" ), user: z.string().optional().describe("A unique user identifier"), });
  • index.ts:138-150 (registration)
    Registration of the create_embeddings tool on the MCP server, including the thin wrapper execute function that calls the core handler.
    server.addTool({ name: "create_embeddings", description: "Create embeddings for text with the Grok API", parameters: embeddings.EmbeddingsRequestSchema, execute: async (args) => { try { const result = await embeddings.createEmbeddings(args); return JSON.stringify(result, null, 2); } catch (err) { handleError(err); } }, });
  • Zod schema for parsing the response from the embeddings API.
    export const EmbeddingsResponseSchema = z.object({ object: z.literal("list"), data: z.array(EmbeddingObjectSchema), model: z.string(), usage: z.object({ prompt_tokens: z.number(), total_tokens: z.number(), }), });
  • Zod schema for individual embedding objects in the response.
    export const EmbeddingObjectSchema = z.object({ object: z.literal("embedding"), embedding: z.array(z.number()), index: z.number(), });

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BrewMyTech/grok-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server