For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
    • Overview
    • Usage for Agents
  • TypeScript SDK
    • Overview
      • Analytics
      • APIKeys
      • Chat
      • Credits
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
      • OAuth
      • Organization
      • Providers
      • Rerank
      • Beta.Responses
      • Speech
      • VideoGeneration
      • Workspaces
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Overview
  • Available Operations
  • generate
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
  • listModels
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
TypeScript SDKAPI Reference

Embeddings - TypeScript SDK

Embeddings method reference
Was this page helpful?
Previous

Endpoints - TypeScript SDK

Endpoints method reference
Next
Built with

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

Overview

Text embedding endpoints

Available Operations

  • generate - Submit an embedding request
  • listModels - List all embeddings models

generate

Submits an embedding request to the embeddings router

Example Usage

1import { OpenRouter } from "@openrouter/sdk";
2
3const openRouter = new OpenRouter({
4 httpReferer: "<value>",
5 appTitle: "<value>",
6 appCategories: "<value>",
7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const result = await openRouter.embeddings.generate({
12 requestBody: {
13 input: "The quick brown fox jumps over the lazy dog",
14 model: "openai/text-embedding-3-small",
15 },
16 });
17
18 console.log(result);
19}
20
21run();

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 httpReferer: "<value>",
8 appTitle: "<value>",
9 appCategories: "<value>",
10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
11});
12
13async function run() {
14 const res = await embeddingsGenerate(openRouter, {
15 requestBody: {
16 input: "The quick brown fox jumps over the lazy dog",
17 model: "openai/text-embedding-3-small",
18 },
19 });
20 if (res.ok) {
21 const { value: result } = res;
22 console.log(result);
23 } else {
24 console.log("embeddingsGenerate failed:", res.error);
25 }
26}
27
28run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreateEmbeddingsRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables 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 httpReferer: "<value>",
5 appTitle: "<value>",
6 appCategories: "<value>",
7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const result = await openRouter.embeddings.listModels();
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 { 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 httpReferer: "<value>",
8 appTitle: "<value>",
9 appCategories: "<value>",
10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
11});
12
13async function run() {
14 const res = await embeddingsListModels(openRouter);
15 if (res.ok) {
16 const { value: result } = res;
17 console.log(result);
18 } else {
19 console.log("embeddingsListModels failed:", res.error);
20 }
21}
22
23run();

Parameters

ParameterTypeRequiredDescription
requestoperations.ListEmbeddingsModelsRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables 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*/*