embeddings
Create embeddings
Section titled “Create embeddings”Create embedding vector representations for input text
Request
Section titled “Request”POST /embeddingsRequest Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | ID of the model to use. You can use the List models API to see all of your available models. |
| input | string | Yes | Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002), cannot be an empty string, and any array must be 2048 dimensions or less. |
| encoding_format | string (float, base64) | No | The format to return the embeddings in. Can be either “float” or “base64”. |
| dimensions | integer | No | The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. |
| user | string | No | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
Request Examples
Section titled “Request Examples”Single text embedding
Section titled “Single text embedding”{ "model": "text-embedding-3-small", "input": "The food was delicious and the waiter was friendly."}Multiple text embeddings
Section titled “Multiple text embeddings”{ "model": "text-embedding-3-small", "input": [ "Hello world", "Goodbye world", "How are you?" ]}Base64 encoded embedding
Section titled “Base64 encoded embedding”{ "model": "text-embedding-3-small", "input": "Convert this to an embedding.", "encoding_format": "base64", "dimensions": 256}Successful response
Response Schema
Section titled “Response Schema”| Field | Type | Required | Description |
|---|---|---|---|
| object | string | Yes | The object type, which is always “list”. |
| data | Array<EmbeddingObject> | Yes | The list of embeddings generated by the model. |
| model | string | Yes | The name of the model used to generate the embedding. |
| usage | object | Yes | The usage information for the request. |
Response Example
Section titled “Response Example”{ "object": "list", "data": [ { "object": "embedding", "embedding": [ 0.0023064255, -0.009327292, -0.0028842222 ], "index": 0 } ], "model": "text-embedding-ada-002", "usage": { "prompt_tokens": 8, "total_tokens": 8 }}Code Examples
Section titled “Code Examples”JavaScript (Fetch)
Section titled “JavaScript (Fetch)”const response = await fetch('https://api.r9s.ai/v1/embeddings', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ "model": "text-embedding-3-small", "input": "The food was delicious and the waiter was friendly."})});
const data = await response.json();console.log(data);Python (requests)
Section titled “Python (requests)”import requests
url = "https://api.r9s.ai/v1/embeddings"headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}
response = requests.post(url, json={ "model": "text-embedding-3-small", "input": "The food was delicious and the waiter was friendly."}, headers=headers)data = response.json()print(data)curl -X POST "https://api.r9s.ai/v1/embeddings" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"text-embedding-3-small","input":"The food was delicious and the waiter was friendly."}'Schema Reference
Section titled “Schema Reference”EmbeddingRequest
Section titled “EmbeddingRequest”| Field | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | ID of the model to use. You can use the List models API to see all of your available models. |
| input | string | Yes | Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002), cannot be an empty string, and any array must be 2048 dimensions or less. |
| encoding_format | string (float, base64) | No | The format to return the embeddings in. Can be either “float” or “base64”. |
| dimensions | integer | No | The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models. |
| user | string | No | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
EmbeddingResponse
Section titled “EmbeddingResponse”| Field | Type | Required | Description |
|---|---|---|---|
| object | string | Yes | The object type, which is always “list”. |
| data | Array<EmbeddingObject> | Yes | The list of embeddings generated by the model. |
| model | string | Yes | The name of the model used to generate the embedding. |
| usage | object | Yes | The usage information for the request. |
EmbeddingObject
Section titled “EmbeddingObject”| Field | Type | Required | Description |
|---|---|---|---|
| object | string | Yes | The object type, which is always “embedding”. |
| embedding | Array | Yes | The embedding vector, which is a list of floats. The length of vector depends on the model. |
| index | integer | Yes | The index of the embedding in the list of embeddings. |
Related APIs
Section titled “Related APIs”- API Overview - Learn about authentication and basic information
- models - View models related APIs
- chat - View chat related APIs
- responses - View responses related APIs
- messages - View messages related APIs
- completions - View completions related APIs
- edits - View edits related APIs
- images - View images related APIs
- engine-embeddings - View engine-embeddings related APIs
- moderations - View moderations related APIs
- audio - View audio related APIs
- search - View search related APIs
- proxy - View proxy related APIs