Skip to main content

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

bash
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.
    • embedding array (required) — The vector representation of the input text, returned as an array of floating-point numbers.
    • index number (required) — The index of the embedding in the list, corresponding to the order of the input items.
    • object string (required) — The type of object, which is always embedding.
  • 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.
    • prompt_tokens number (required) — The number of tokens in the input prompt.
    • total_tokens number (required) — The total number of tokens consumed by the request.

Example Response

Example Response

json
{
  "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.