Embeddings - TypeScript SDK

Embeddings method reference

The TypeScript SDK and docs are currently in beta. Report issues on GitHub.

(embeddings)

Overview

Text embedding endpoints

Available Operations

generate

Submits an embedding request to the embeddings router

Example Usage

1import { OpenRouter } from "@openrouter/sdk";
2
3const openRouter = new OpenRouter({
4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
5});
6
7async function run() {
8 const result = await openRouter.embeddings.generate({
9 input: "<value>",
10 model: "Taurus",
11 });
12
13 console.log(result);
14}
15
16run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { embeddingsGenerate } from "@openrouter/sdk/funcs/embeddingsGenerate.js";
3
4// Use `OpenRouterCore` for best tree-shaking performance.
5// You can create one instance of it to use across an application.
6const openRouter = new OpenRouterCore({
7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const res = await embeddingsGenerate(openRouter, {
12 input: "<value>",
13 model: "Taurus",
14 });
15 if (res.ok) {
16 const { value: result } = res;
17 console.log(result);
18 } else {
19 console.log("embeddingsGenerate failed:", res.error);
20 }
21}
22
23run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreateEmbeddingsRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions 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.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CreateEmbeddingsResponse>

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.PaymentRequiredResponseError402application/json
errors.NotFoundResponseError404application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.BadGatewayResponseError502application/json
errors.ServiceUnavailableResponseError503application/json
errors.EdgeNetworkTimeoutResponseError524application/json
errors.ProviderOverloadedResponseError529application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

listModels

Returns a list of all available embeddings models and their properties

Example Usage

1import { OpenRouter } from "@openrouter/sdk";
2
3const openRouter = new OpenRouter({
4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
5});
6
7async function run() {
8 const result = await openRouter.embeddings.listModels();
9
10 console.log(result);
11}
12
13run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { embeddingsListModels } from "@openrouter/sdk/funcs/embeddingsListModels.js";
3
4// Use `OpenRouterCore` for best tree-shaking performance.
5// You can create one instance of it to use across an application.
6const openRouter = new OpenRouterCore({
7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const res = await embeddingsListModels(openRouter);
12 if (res.ok) {
13 const { value: result } = res;
14 console.log(result);
15 } else {
16 console.log("embeddingsListModels failed:", res.error);
17 }
18}
19
20run();

Parameters

ParameterTypeRequiredDescription
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions 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.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<models.ModelsListResponse>

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*