Table of Contents [expand]
Last updated February 12, 2026
The Cohere Embed Multilingual (cohere-embed-multilingual) model generates vector embeddings (lists of numbers) for provided text inputs. These embeddings can be used in various applications, such as search, classification, and clustering. This guide describes how to access the /v1/embeddings API using JavaScript.
Prerequisites
Before making requests, provision access to the model of your choice.
Attach a Managed Inference and Agents add-on to an app:
# If you don't have an app, create one and specify the name for your app. Or, skip this step to use an existing app: heroku create $APP_NAME # Create and attach the Managed Inference and Agents add-on to your app, $APP_NAME: heroku addons:create heroku-inference:standard -a $APP_NAME --as INFERENCEInstall the necessary
axiospackage:npm install axios
JavaScript Example Code
const axios = require('axios');
// Assert that environment variables are set
const EMBEDDING_URL = process.env.EMBEDDING_URL;
const EMBEDDING_KEY = process.env.EMBEDDING_KEY;
if (!EMBEDDING_URL || !EMBEDDING_KEY) {
console.error("Missing required environment variables.");
console.log("Set them up using the following commands:");
console.log("export EMBEDDING_URL=$(heroku config:get -a $APP_NAME EMBEDDING_URL)");
console.log("export EMBEDDING_KEY=$(heroku config:get -a $APP_NAME EMBEDDING_KEY)");
process.exit(1);
}
async function parseEmbeddingOutput(response) {
if (response.status === 200) {
console.log("Embeddings:", response.data.data);
} else {
console.log(`Request failed: ${response.status}, ${response.statusText}`);
}
}
async function generateEmbeddings(payload) {
try {
const response = await axios.post(`${EMBEDDING_URL}/v1/embeddings`, payload, {
headers: {
'Authorization': `Bearer ${EMBEDDING_KEY}`,
'Content-Type': 'application/json'
}
});
await parseEmbeddingOutput(response);
} catch (error) {
console.error("Error generating embeddings:", error.message);
}
}
// Example payload
const payload = {
model:"cohere-embed-multilingual",
input: ["Hello, I am a blob of text.", "How's the weather in Portland?"],
input_type: "search_document",
truncate: "END",
encoding_format: "float"
};
// Generate embeddings
generateEmbeddings(payload);