Skip to main content
Generate embeddings and receive the complete raw API response including all metadata. Use this when you need access to token usage, model information, or other response details not included in the standard openai_embed() function.

Samples

Get raw embedding response

Receive the full API response:
SELECT ai.openai_embed_with_raw_response(
    'text-embedding-ada-002',
    'PostgreSQL is powerful'
);

Extract token usage

Check how many tokens were used:
SELECT
    (ai.openai_embed_with_raw_response(
        'text-embedding-ada-002',
        'sample text'
    )->>'usage')::jsonb;

Arguments

This function accepts the same arguments as openai_embed().

Returns

JSONB: The complete API response including:
  • object: Response type
  • data: Array of embedding objects
  • model: Model used
  • usage: Token usage information
  • openai_embed(): standard embedding function returning just the vector