> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyone.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /v1/embeddings — generate text embeddings

> POST /v1/embeddings converts text into dense vectors. Use for semantic search, RAG pipelines, document clustering, and classification. OpenAI-compatible format.

The `/v1/embeddings` endpoint converts one or more text strings into dense vector representations (embeddings). You can use these vectors to find semantically similar content, build retrieval-augmented generation (RAG) pipelines, cluster documents, or train classifiers. Anyone is compatible with the OpenAI Embeddings API format, so any OpenAI-compatible embedding client works without modification.

***

## POST /v1/embeddings

### Request body

<ParamField body="model" type="string" required>
  The embedding model to use. For example, `text-embedding-3-small`, `text-embedding-3-large`, or `text-embedding-ada-002`. The available models depend on your configured channels.
</ParamField>

<ParamField body="input" type="string | string[]" required>
  The text to embed. Can be a single string or an array of strings. Each string is embedded independently. Arrays are useful for batch embedding multiple documents in one request.
</ParamField>

<ParamField body="encoding_format" type="string">
  The format of the returned embedding vectors. `float` returns an array of floating-point numbers; `base64` returns a base64-encoded binary string. Defaults to `float`.
</ParamField>

<ParamField body="dimensions" type="integer">
  The number of dimensions for the output embedding vector. Supported only by certain models (e.g., `text-embedding-3-small` and `text-embedding-3-large`). Truncates the embedding to the specified length.
</ParamField>

<ParamField body="user" type="string">
  An optional identifier for the end user making the request. Used for monitoring and abuse detection on the provider side.
</ParamField>

### Response

<ResponseField name="object" type="string">
  Always `"list"`.
</ResponseField>

<ResponseField name="model" type="string">
  The model that generated the embeddings.
</ResponseField>

<ResponseField name="data" type="object[]">
  An array of embedding objects, one per input string.

  <Expandable title="embedding object properties">
    <ResponseField name="object" type="string">
      Always `"embedding"`.
    </ResponseField>

    <ResponseField name="index" type="integer">
      The position of this embedding in the input array, starting at `0`.
    </ResponseField>

    <ResponseField name="embedding" type="number[]">
      The embedding vector as an array of floating-point numbers. The length equals the model's output dimension, or the value of `dimensions` if specified.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage for the request.

  <Expandable title="usage properties">
    <ResponseField name="prompt_tokens" type="integer">
      Number of tokens in the input.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      Total tokens processed (same as `prompt_tokens` for embeddings).
    </ResponseField>
  </Expandable>
</ResponseField>

***

### Examples

<CodeGroup>
  ```bash curl theme={null}
  curl https://api.anyone.ai/v1/embeddings \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "text-embedding-3-small",
      "input": [
        "Anyone is a unified AI gateway.",
        "You can embed multiple strings in one request."
      ],
      "encoding_format": "float"
    }'
  ```

  ```python python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_TOKEN",
      base_url="https://api.anyone.ai/v1",
  )

  response = client.embeddings.create(
      model="text-embedding-3-small",
      input=[
          "Anyone is a unified AI gateway.",
          "You can embed multiple strings in one request.",
      ],
  )

  for item in response.data:
      print(f"Index {item.index}: {len(item.embedding)} dimensions")
  ```
</CodeGroup>

***

## Common use cases

* **Semantic search** — embed your document corpus and a user query, then rank documents by cosine similarity to the query vector.
* **Retrieval-augmented generation (RAG)** — retrieve the most relevant chunks from a knowledge base before passing them to a language model.
* **Clustering** — group semantically related documents without labeled training data.
* **Classification** — use embedding vectors as features for downstream classifiers.
