openai_embed() function.
Samples
Get raw embedding response
Receive the full API response:Extract token usage
Check how many tokens were used:Arguments
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
model | TEXT | - | ✔ | The OpenAI embedding model to use (e.g., text-embedding-ada-002, text-embedding-3-small) |
input_text | TEXT | - | ✔ | Single text input to embed (use this OR input_texts OR input_tokens) |
input_texts | TEXT[] | - | ✔ | Array of text inputs to embed in a batch |
input_tokens | INT[] | - | ✔ | Pre-tokenized input as an array of token IDs |
api_key | TEXT | NULL | ✖ | OpenAI API key. If not provided, uses ai.openai_api_key setting |
api_key_name | TEXT | NULL | ✖ | Name of the secret containing the API key |
dimensions | INT | NULL | ✖ | Number of dimensions for the output embedding (only supported by some models) |
openai_user | TEXT | NULL | ✖ | Unique identifier for the end-user for abuse monitoring |
encoding_format | TEXT | NULL | ✖ | Format for the embeddings (float or base64) |
extra_headers | JSONB | NULL | ✖ | Additional HTTP headers to include in the API request |
extra_query | JSONB | NULL | ✖ | Additional query parameters for the API request |
verbose | BOOLEAN | FALSE | ✖ | Enable verbose logging for debugging |
client_config | JSONB | NULL | ✖ | Advanced client configuration options |
Returns
JSONB: The complete API response including:
object: Response typedata: Array of embedding objectsmodel: Model usedusage: Token usage information
Related functions
openai_embed(): standard embedding function returning just the vector