Embeddings

Last updated:

|Edit this page|

On this page

Embeddings are calls to embedding models that convert text into vector representations for semantic search, RAG pipelines, and similarity matching.

While generations track LLM conversations and spans track operations, embeddings specifically monitor vector generation:

  • Search queries - Converting user input for semantic search
  • Document indexing - Embedding content for retrieval
  • RAG pipelines - Query and document vectorization
  • Batch processing - Multiple embeddings in one call

For technical implementation details, see manual capture.

Event properties

An embedding is a single call to an embedding model to convert text into a vector representation.

Event Name: $ai_embedding

PropertyDescription
$ai_trace_idThe trace ID (a UUID to group related AI events together)
Must contain only letters, numbers, and special characters: -, _, ~, ., @, (, ), !, ', :, |
Example: d9222e05-8708-41b8-98ea-d4a21849e761
$ai_modelThe embedding model used
Example: text-embedding-3-small, text-embedding-ada-002
$ai_providerThe LLM provider
Example: openai, cohere, voyage
$ai_inputThe text to embed
Example: "Tell me a fun fact about hedgehogs" or array of strings for batch embeddings
$ai_input_tokensThe number of tokens in the input
$ai_latencyOptional
The latency of the embedding call in seconds
$ai_http_statusOptional
The HTTP status code of the response
$ai_base_urlOptional
The base URL of the LLM provider
Example: https://api.openai.com/v1
$ai_request_urlOptional
The full URL of the request made to the embedding API
Example: https://api.openai.com/v1/embeddings
$ai_is_errorOptional
Boolean to indicate if the request was an error
$ai_errorOptional
The error message or object if the embedding failed
Cost PropertiesOptional - If not provided, costs will be calculated automatically from token counts
$ai_input_cost_usdOptional
The cost in USD of the input tokens
$ai_output_cost_usdOptional
The cost in USD of the output tokens (usually 0 for embeddings)
$ai_total_cost_usdOptional
The total cost in USD
Span/Trace Properties
$ai_span_idOptional
Unique identifier for this embedding operation
$ai_span_nameOptional
Name given to this embedding operation
Example: embed_user_query, index_document
$ai_parent_idOptional
Parent span ID for tree view grouping

Example

Terminal
curl -X POST "https://us.i.posthog.com/i/v0/e/" \
-H "Content-Type: application/json" \
-d '{
"api_key": "<ph_project_api_key>",
"event": "$ai_embedding",
"properties": {
"distinct_id": "user_123",
"$ai_trace_id": "d9222e05-8708-41b8-98ea-d4a21849e761",
"$ai_model": "text-embedding-3-small",
"$ai_provider": "openai",
"$ai_input": "What are the key features of product analytics at PostHog?",
"$ai_input_tokens": 12,
"$ai_latency": 0.234,
"$ai_http_status": 200,
"$ai_base_url": "https://api.openai.com/v1",
"$ai_request_url": "https://api.openai.com/v1/embeddings",
"$ai_is_error": false,
"$ai_span_name": "embed_search_query",
"$ai_span_id": "bdf42359-9364-4db7-8958-c001f28c9255",
"$ai_parent_id": "537b7988-0186-494f-a313-77a5a8f7db26"
},
"timestamp": "2025-01-30T12:00:00Z"
}'

Questions? Ask Max AI.

It's easier than reading through 728 pages of documentation

Community questions

Was this page useful?

Next article

Calculating LLM costs

How are LLM costs calculated? PostHog calculates cost based on the number of input (prompt) and output (completion) tokens generated by specific AI models matching on the model name, $ai_model , sent in the event. We use OpenRouter's API to fetch the prices for each model whenever possible and fall back to manually setting prices for models that OpenRouter doesn't support. For cached LLM response, we apply discounts to reflect the reduced costs. For example, cached tokens are charged at 50% of…

Read next article