Embeddings


This document provides a detailed specification for the AIGNE Hub Embeddings API endpoint. By following this guide, you will learn how to convert text into numerical vector representations, a foundational step for tasks like semantic search, text clustering, and similarity analysis.

Create embedding#

Generates a vector representation for a given text input. This is useful for machine learning applications that require a numerical representation of text.

POST /api/embeddings

Request Body#

model
string
required

The ID of the model to use for generating the embeddings. The model must be compatible with embedding tasks.

input
string or array
required

The input text or tokens to embed. This can be a single string, an array of strings, an array of integers (tokens), or an array of integer arrays (batched tokens).

Example Request#

Here is an example of how to call the embeddings endpoint using cURL.

Create an embedding request

curl https://your-aigne-hub-instance.com/api/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "AIGNE Hub is a unified AI gateway."
  }'

Response Body#

The API returns an object containing the list of embedding data.

data
array
required

An array of embedding objects, where each object corresponds to an input item.

3 subfields
model
string
required

The model that was used to generate the embeddings.

object
string
required

The type of the top-level object, which is always list.

usage
object
required

An object detailing the token usage for the request.

2 subfields

Example Response#

Example Response

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        -0.006929283495992422,
        -0.005336422007530928,
        ...
        -4.547132266452536e-05
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-3-small",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

Summary#

The Embeddings API provides a straightforward method for converting text into high-dimensional vectors, enabling a wide range of natural language processing applications. For building more complex conversational or generative AI, you may also want to explore the Chat Completions API.