Interface EmbeddingResponse

Represents the response from an embedding generation request. This structure includes the generated embeddings, information about the model and provider used, token usage details, and any errors encountered during processing (especially relevant for batch requests).

EmbeddingResponse

interface EmbeddingResponse {
    embeddings: number[][];
    modelId: string;
    providerId: string;
    usage: {
        inputTokens?: number;
        totalTokens: number;
        costUSD?: number;
    };
    errors?: {
        textIndex: number;
        message: string;
        details?: any;
    }[];
}

Properties

embeddings: number[][]

An array of embedding vectors. Each inner array (number[]) corresponds to an input text from the EmbeddingRequest. The order is preserved. If an error occurred for a specific text in a batch, its corresponding entry might be missing, or represented by a specific error object if partial results are supported differently. The errors array should be checked.

Example

[[0.1, 0.2, ...], [0.3, 0.4, ...]]
modelId: string

The ID of the embedding model that was actually used to generate the embeddings. This is important for consistency, especially if model selection was dynamic.

Example

"text-embedding-3-small"
providerId: string

The ID of the LLM provider that was used.

Example

"openai"
usage: {
    inputTokens?: number;
    totalTokens: number;
    costUSD?: number;
}

Information about token usage and cost for the embedding generation.

Type declaration

  • Optional inputTokens?: number
  • totalTokens: number
  • Optional costUSD?: number
errors?: {
    textIndex: number;
    message: string;
    details?: any;
}[]

Optional: An array of error objects, relevant if processing a batch of texts and some individual texts failed. If the entire request failed catastrophically, the generateEmbeddings method itself should throw an error.

Type declaration

  • textIndex: number
  • message: string
  • Optional details?: any

Optional

Example

errors: [{ textIndex: 1, message: "Content policy violation", details: { reason: "unsafe_content" } }]