Embeddings - Python SDK

Embeddings method reference

The Python 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

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 api_key=os.getenv("OPENROUTER_API_KEY", ""),
6) as open_router:
7
8 res = open_router.embeddings.generate(input="<value>", model="Taurus", provider={
9 "data_collection": "allow",
10 "zdr": True,
11 "enforce_distillable_text": True,
12 "order": [
13 "OpenAI",
14 ],
15 "only": [
16 "OpenAI",
17 ],
18 "ignore": [
19 "OpenAI",
20 ],
21 "quantizations": [
22 "fp16",
23 ],
24 "sort": "price",
25 })
26
27 # Handle response
28 print(res)

Parameters

ParameterTypeRequiredDescription
inputoperations.InputUnion✔️N/A
modelstr✔️N/A
encoding_formatOptional[operations.EncodingFormat]N/A
dimensionsOptional[int]N/A
userOptional[str]N/A
providerOptional[operations.CreateEmbeddingsProvider]N/A
input_typeOptional[str]N/A
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

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*/*

list_models

Returns a list of all available embeddings models and their properties

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 api_key=os.getenv("OPENROUTER_API_KEY", ""),
6) as open_router:
7
8 res = open_router.embeddings.list_models()
9
10 # Handle response
11 print(res)

Parameters

ParameterTypeRequiredDescription
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

components.ModelsListResponse

Errors

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