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

# Embeddings API

> Use CometAPI embeddings routes to create vectors for semantic search, clustering, recommendations, and retrieval workflows.

Use CometAPI embeddings when your app needs vectors for semantic search, clustering, recommendations, or retrieval. Send text to `/v1/embeddings`, store the returned vector, and search it with your vector database.

## Create an embedding

Use an embedding-capable model ID from the [Models page](/overview/models) or the [model directory](https://www.cometapi.com/models/). The examples below call the OpenAI-compatible Embeddings API.

<Note>
  These examples use the placeholder `your-embedding-model-id`. Replace it with an available embedding model ID from the [Models page](/overview/models) or [model directory](https://www.cometapi.com/models/) before you run the request.
</Note>

<Tip>
  Open [Create embeddings](/api/text/embeddings) to use the playground and endpoint schema.
</Tip>

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  response = requests.post(
      "https://api.cometapi.com/v1/embeddings",
      headers={
          "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
          "Content-Type": "application/json",
      },
      json={
          "model": "your-embedding-model-id",
          "input": "CometAPI lets developers use many model providers.",
      },
      timeout=30,
  )

  response.raise_for_status()
  result = response.json()
  print(len(result["data"][0]["embedding"]))
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.cometapi.com/v1/embeddings", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "your-embedding-model-id",
      input: "CometAPI lets developers use many model providers.",
    }),
  });

  if (!response.ok) {
    throw new Error(await response.text());
  }

  const result = await response.json();
  console.log(result.data[0].embedding.length);
  ```

  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/embeddings \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "your-embedding-model-id",
      "input": "CometAPI lets developers use many model providers."
    }'
  ```
</CodeGroup>

## Response example

A successful response can look like this. The response includes one vector for each input item; the vector below is shortened for readability:

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        -0.0021,
        -0.0491,
        0.0209
      ]
    }
  ],
  "model": "your-embedding-model-id",
  "usage": {
    "prompt_tokens": 10,
    "total_tokens": 10
  }
}
```

## Batch input

Send an array of strings when you want several vectors from one request:

```bash cURL theme={null}
curl https://api.cometapi.com/v1/embeddings \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-embedding-model-id",
    "input": [
      "Create an API key",
      "Change the base URL",
      "Retry after a rate limit"
    ]
  }'
```

## Example model records

<Info>
  This example model catalog response shows the `/api/models` envelope and one OpenAI-compatible embedding model record shape. Some embedding records use an empty `model_type`; choose an embedding model by ID and endpoint support instead of relying on that field alone.
</Info>

```bash cURL theme={null}
curl https://api.cometapi.com/api/models
```

```json theme={null}
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1757904564,
      "id": "your-embedding-model-id",
      "code": "your-embedding-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example embedding model",
      "model_type": "embedding",
      "features": [
        "text-embedding"
      ],
      "endpoints": [
        "openai"
      ],
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 0.1,
        "output": null,
        "per_request": null,
        "per_second": null
      }
    }
  ]
}
```

## Common errors

<AccordionGroup>
  <Accordion title="Input too long">
    Split long documents into chunks before embedding.
  </Accordion>

  <Accordion title="Wrong model type">
    Choose an embedding-capable model from the model directory.
  </Accordion>

  <Accordion title="Vector dimensions mismatch">
    Keep the same model and dimensions for one vector index.
  </Accordion>

  <Accordion title="Missing API key">
    Send `Authorization: Bearer $COMETAPI_KEY`.
  </Accordion>
</AccordionGroup>

## Error codes and retry strategy

<AccordionGroup>
  <Accordion title="400">
    Do not retry until the input, model ID, or dimensions setting is fixed.
  </Accordion>

  <Accordion title="401">
    Do not retry until the API key is present and valid.
  </Accordion>

  <Accordion title="404">
    Check the base URL, path, and model ID before retrying.
  </Accordion>

  <Accordion title="429">
    Retry with exponential backoff and reduce batch size or concurrency.
  </Accordion>

  <Accordion title="500 or 503">
    Retry with backoff for transient provider or service errors.
  </Accordion>
</AccordionGroup>

<Tip>
  For implementation patterns, see [Error codes and retry strategy](/guides/error-codes-and-retry-strategy) and [Rate limits and concurrency](/guides/rate-limits-and-concurrency).
</Tip>

## Pricing and model directory

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    Read how CometAPI exposes model IDs in the docs.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    Browse model availability and capabilities.
  </Card>

  <Card title="Pricing" icon="tag" href="https://www.cometapi.com/pricing/">
    Check pricing before you call a model.
  </Card>
</CardGroup>
