Skip to main content

Embeddings

POST https://gateway-api.mastra.ai/v1/embeddings

Compatible with the OpenAI Embeddings API. input accepts a string, an array of strings, or token arrays.

import OpenAI from 'openai'

const client = new OpenAI({
apiKey: process.env.MASTRA_GATEWAY_API_KEY,
baseURL: 'https://gateway-api.mastra.ai/v1',
})

const result = await client.embeddings.create({
model: 'openai/text-embedding-3-small',
input: ['first document', 'second document'],
})

console.log(result.data[0].embedding.length)

From a Mastra application, use the model router:

import { ModelRouterEmbeddingModel } from '@mastra/core/llm'

const embedder = new ModelRouterEmbeddingModel('mastra/openai/text-embedding-3-small')