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

# Embeddings

> Generate vector embeddings from text using OpenAI's embedding models through Prisma AIRS AI Gateway.

OpenAI's embedding models transform text into lists of floating-point numbers (vectors). Smaller distances between vectors indicate higher semantic similarity, making them useful for semantic search, content clustering, recommendations, and anomaly detection.

## Usage

```sh cURL theme={"system"}
curl https://aigw.portkey.ai/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $PORTKEY_API_KEY" \
  -H "x-portkey-provider: $PORTKEY_PROVIDER" \
  -d '{
    "input": "Your text string goes here",
    "model": "text-embedding-3-small"
  }'
```

```py OpenAI Python SDK theme={"system"}
from openai import OpenAI

client = OpenAI(
    api_key="PORTKEY_API_KEY",
    base_url="https://aigw.portkey.ai/v1"
)

response = client.embeddings.create(
    input="Your text string goes here",
    model="@OPENAI_PROVIDER/text-embedding-3-small"
)

print(response.data[0].embedding)
```

```ts OpenAI Node.js SDK theme={"system"}
import OpenAI from 'openai';

const openai = new OpenAI({
    apiKey: "PORTKEY_API_KEY",
    baseURL: "https://aigw.portkey.ai/v1"
});

const response = await openai.embeddings.create({
    input: "Your text string goes here",
    model: "@OPENAI_PROVIDER/text-embedding-3-small"
});

console.log(response.data[0].embedding);
```

## Supported Models

| Model | Dimensions | Notes |
| - | - | - |
| `text-embedding-3-small` | 1536 | Best cost/performance ratio |
| `text-embedding-3-large` | 3072 | Highest accuracy |
| `text-embedding-ada-002` | 1536 | Legacy model |

## Supported Parameters

| Parameter | Type | Description |
| - | - | - |
| `model` | string | Embedding model ID |
| `input` | string or array | Text to embed. Pass an array to embed multiple strings in one request |
| `encoding_format` | string | `float` (default) or `base64` |
| `dimensions` | integer | Reduce output dimensions (supported on v3 models only) |
| `user` | string | End-user ID for tracking |

## FAQs

> **How can I tell how many tokens a string has before I embed it?**
>
> Use OpenAI's [Tiktoken library](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) to count tokens before making an embedding request.

> **How can I retrieve K nearest embedding vectors quickly?**
>
> Use a specialized vector database. See [OpenAI's vector database cookbook](https://cookbook.openai.com/examples/vector_databases/readme) for options and examples.

> **Do V3 embedding models know about recent events?**
>
> The knowledge cutoff for `text-embedding-3-large` and `text-embedding-3-small` is September 2021.


## Related topics

- [Embeddings](https://docs.portkey.ai/docs/aigw/integrations/llms/bedrock/embeddings.md)
- [Create embedding](https://docs.portkey.ai/docs/aigw/api-reference/embeddings/create-embedding.md)
- [Guardrails for Embedding Requests](https://docs.portkey.ai/docs/aigw/product/guardrails/embedding-guardrails.md)
- [Langchain (JS/TS)](https://docs.portkey.ai/docs/aigw/integrations/libraries/langchain-js.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.