AI SDK Event Data Reference

The Countly AI SDK records LLM activity as four standard Countly events. This article lists every field on each of them, explains how to tell a missing value from a real zero, and shows which adapter can observe which signal.

It is written for developers who query these events in Drill, build their own reports, or export the raw data. Every field described here belongs to schema_version 2.

Overview of the Event Keys

Event Key One Event Per Sent From Observability Level
[CLY]_llm_interaction LLM generation 0 (always)
[CLY]_llm_tool_used Tool or MCP call 1
[CLY]_llm_tool_usage_parameter Tool call argument 2
[CLY]_llm_interaction_feedback Feedback you record Any level

An interaction event means exactly one LLM generation. A multi-step agent turn emits one interaction event per generation, and a trace that contained no generation, such as a Mastra workflow that never called a model, emits no interaction event at all. Its tool events are still sent.

Understanding Sentinels and Omitted Values

The SDK never guesses. Every field follows one of two rules, depending on whether it is a dimension you group by or a measure you add up.

Dimensions Always Have a Value

A dimension, such as model, provider, status, or finish_reason, is always present on the event that owns it. When the adapter cannot observe it, the SDK writes an explicit sentinel: "unknown" or "not_reported".

So a sentinel means "this adapter could not see it", not "something unusual happened". A missing dimension only ever means you are looking at the wrong event key.

Measures Are Omitted When Not Measured

A measure, such as a token count, a cost, or a latency, is left out entirely when it was not measured. Two markers, always present on the interaction event, tell you why:

Marker Value Meaning
usage_state reported The provider reported token usage. The usage_* fields are present.
usage_state not_reported No usage was reported. Every usage_* and cost_* field is omitted.
cost_priced priced The model has a price. The cost_* fields are present.
cost_priced priced_modality_approx The cost_* fields are present.
cost_priced unpriced_model The model is not in the pricing table and has no costModel override. The cost_* fields are omitted.
cost_priced no_usage There was no usage to price. The cost_* fields are omitted.

Show a dash, not a zero

A cost of 0 never means "no price for this model", and a token count of 0 never means "the provider told us nothing". In your own reports and exports, render an omitted measure as — or "unpriced". Treating it as 0 makes averages and totals look lower than they are.

The same rule applies to optional measures. For example, usage_cache_read: 0 is a measured cache miss, while an absent usage_cache_read means the provider does not report caching. Likewise, latency_total is omitted, never 0, when it was not measured.

Common Envelope Fields

These fields are stamped on every event of all four keys, so you can filter any of them the same way.

Field Type Description
event_id string UUID. The only primary key of an event.
run_id string The turn or call the event belongs to. Join on it across all four keys.
schema_version number 2. An integer, so you can range-query it.
sdk_version string Version of the adapter package
sdk_core_version string Version of @countly/ai-sdk-core
sdk_adapter string Which adapter sent the event
environment string From the environment setting, e.g., production
source string From the source setting, e.g., api or chat
thread_id string Conversation grouping, when the adapter can observe it
tags string Your tags setting, joined with commas

The event timestamp is in milliseconds. The hour and dow (day of week) values are in UTC, whatever the time zone of the machine running your application. They are computed once per turn, so every event of one turn has the same values. Branch your queries on schema_version, not on sdk_version.

Identity and Joining Events

Three fields identify an event and connect it to others. Only one of them is unique.

Field What It Identifies
event_id This event. Unique.
run_id The turn. Your getPromptId() value when you supply one, otherwise an ID the adapter generates or reads from the framework.
prompt_id The parent event this one belongs to. A foreign key, not an identity.

What prompt_id points to depends on the event key, and parent_event_key tells you which kind of parent it is: "[CLY]_llm_interaction" or "run".

Event Key prompt_id Points To
[CLY]_llm_interaction Its own event_id: a generation is its own parent
[CLY]_llm_tool_used and [CLY]_llm_tool_usage_parameter The generation that requested the tool, or the run when there is none
[CLY]_llm_interaction_feedback The run by default, or one generation when feedback was recorded against its event_id

Count generations by event_id

prompt_id is not unique on interaction events when your application supplies one ID per turn. Use event_id to count events, and run_id to group a turn.

Interaction Event Fields

Each [CLY]_llm_interaction event describes one generation. It carries the envelope above plus the fields below.

Always-Present Dimensions

Field Values
model The model actually used, or unknown
provider The vendor, e.g., openai, anthropic, google, or cohere, or unknown
api_host_type vendor_direct, azure_openai, gateway, local_infra, or unknown
status success, error, incomplete, or unknown
finish_reason stop, length, tool_calls, content_filter, error, other, or not_reported
usage_state, cost_priced The markers described in Understanding Sentinels and Omitted Values
generation_index Position of this generation within the run, starting at 0
prompt_id, parent_event_key See Identity and Joining Events

status: "incomplete" marks a generation that did not finish, e.g., an abandoned Cohere stream, or a Mastra turn still running when shutdown() was called. The tokens may still have been billed.

Token and Cost Measures

These are present only when the matching marker says so. All token counts are numbers.

Field Present When Description
usage_input usage_state is reported The provider's total input, including cache reads and cache writes
usage_input_fresh usage_state is reported Input left after the cache and modality buckets
usage_output usage_state is reported The provider's total output, including reasoning
usage_total usage_state is reported usage_input plus usage_output
usage_cache_read, usage_cache_write The provider reports caching Subsets of usage_input
usage_reasoning The provider reports reasoning tokens Subset of usage_output
usage_output_text Something else shares the output bucket Output left after reasoning and modality tokens
usage_input_audio, usage_input_image, usage_output_audio, usage_output_image The provider reports them Modality subsets of input or output
cost_input, cost_output, cost_total cost_priced is priced or priced_modality_approx Cost in dollars
cost_cache_read, cost_cache_write, cost_reason, cost_cache_saved As above, and the value is not zero Cost components, plus what cache reads saved

The token fields always add up, because the SDK derives the sub-buckets instead of trusting them:

  • usage_total equals usage_input plus usage_output.
  • usage_input equals usage_input_fresh plus cache reads, cache writes, input audio, and input image tokens.
  • usage_output equals usage_output_text plus reasoning, output audio, and output image tokens.

Cost components are disjoint: every token is billed once, so cost_total is the plain sum of cost_input (fresh input only), cost_cache_read, cost_cache_write, cost_output, and cost_reason. cost_cache_saved is reported alongside and is not part of the sum. See Understanding and Customizing AI Cost Calculation for the details.

Optional Fields

Field Description
latency_total This generation's duration in milliseconds
run_latency_total The whole turn's duration in milliseconds, repeated on every generation of the turn
latency_ttft Time to first token in milliseconds
api_host Hostname of the endpoint only. The path, query, and credentials are never sent.
tools_requested, tool_request_count Comma-separated names of the tools this generation asked for, and how many calls. Sent at every level, including 0.
finish_reason_raw The provider's own wording, only when finish_reason is other
model_requested The requested model, only when it differs from model
response_id, response_model The provider's response ID and the model it echoed back
config_temperature, config_top_p, config_max_tokens, config_frequency_penalty, config_presence_penalty, config_stream Request settings
agent_name, workflow_name, step_count Agent, workflow, and step count (Mastra)
trace_id, span_id, parent_span_id, parent_prompt_id Trace and agent chain hierarchy
error The error message
text_input_preview, text_output_preview, text_reasoning_preview Level 2 only. Capped at textPreviewLength (200 characters by default), with system and tool messages filtered out. Each has a *_state field set to complete or truncated.
provider_metadata Provider-specific fields, including provider_id, the raw provider ID before normalization (e.g., openai.responses)

Provider Metadata by Adapter

The keys inside provider_metadata depend on the adapter, and appear only when the provider's response contains them.

Adapter Keys
OpenAI system_fingerprint, service_tier, accepted_prediction_tokens, rejected_prediction_tokens, audio_tokens_prompt, audio_tokens_completion, logprobs
Anthropic stop_sequence, container, service_tier, inference_geo, server_tool_use, cache_creation
Google GenAI model_version, create_time, traffic_type, usage_tool_use_prompt_tokens, safety_ratings, grounding_metadata, citation_metadata, logprobs_result, avg_logprobs
Cohere tool_plan, citations, documents, search_queries, search_results, is_search_required, billed_units, api_version
Vercel AI SDK experimental_providerMetadata, providerMetadata, tool_results, steps_count, warnings, sources, files
LangChain tags, metadata, run_name, generation_info, llm_output
LlamaIndex source_nodes (with score, node_id, and metadata), system_fingerprint, service_tier
Mastra Mastra's own provider metadata, with per-provider sub-keys, e.g., openai.systemFingerprint or anthropic.stopSequence

Tool Event Fields

Both tool keys carry the envelope and are scoped by run_id, so tool calls from a trace with no generation are still reported.

Tool Calls

One [CLY]_llm_tool_used event is sent per tool or MCP call, at observability level 1 and above.

Field Description
prompt_id, parent_event_key The requesting generation, or the run
tool_name The tool's name. Mastra workflow steps use the step ID, with hyphens replaced by underscores.
type function_call, mcp_tool_call, retrieval, or code_interpreter
status success, error, or unknown when the outcome cannot be observed
call_id ID of this invocation, so two calls of the same tool in one turn stay distinct
latency Tool execution time in milliseconds, when observed
error The tool's error message
agent_name, workflow_name, trace_id Copied from the parent, so you can break tool usage down by agent

Tool Call Arguments

One [CLY]_llm_tool_usage_parameter event is sent per argument of each tool call, at observability level 2 only.

Field Description
prompt_id, parent_event_key As on tool call events
tool_name, call_id The tool and the invocation the argument belongs to
param_name The argument's name
param_value The argument's value, capped at paramValueLength (1024 characters by default, 8192 at most)
param_value_state complete or truncated
param_value_length The original length, present only when the value was truncated
agent_name, workflow_name, trace_id Copied from the parent

An argument that cannot be serialized at all, e.g., a circular object, is left out rather than sent as a placeholder.

Feedback Event Fields

A [CLY]_llm_interaction_feedback event is sent each time your application records feedback, and Mastra also sends its own scorer results and feedback this way. It carries the envelope plus these fields:

Field Description
prompt_id What is rated: the run by default, or one generation's event_id
run_id The run the feedback belongs to
parent_event_key "run" or "[CLY]_llm_interaction"
rating thumbs_up, thumbs_down, or a custom string
rating_kind binary, score, category, or other. Derived by the SDK.
score Numeric score from 0 to 1
category e.g., hallucination, irrelevant, or harmful
comment Free-form text
model, provider, agent_name, workflow_name, trace_id Copied onto the feedback event, so you can break feedback down without joining to an interaction outside your time range

Filter on rating_kind before you aggregate, so numeric scores are not mixed into a thumbs-up rate. See Collecting User Feedback on AI Responses for how to record feedback.

Besides these four events, the SDK sends failed LLM calls to Crash AnalyticsCrashes as crash reports, and measured latencies to Performance Monitoring as traces. Traces require Countly Enterprise: Community Edition ignores them..

What Each Adapter Can Observe

A missing or sentinel value usually means the adapter cannot physically observe that signal, not that something is broken. Every adapter reports token usage, cost, cache reads, streaming, tool calls with call_id, request settings, text previews, and errors. The signals that differ are below.

Signal OpenAI Anthropic Google GenAI Cohere Vercel AI SDK LangChain LlamaIndex Mastra
Interaction events per turn One per call One per call One per call One per call One per step One per LLM run One per LLM call One per generation span
run_id without getPromptId Per call Per call Per call Per call Per call Root run Per call Per trace
usage_cache_write No Yes No No Yes Yes Yes Yes
usage_reasoning Yes No Yes No Yes Yes Yes Yes
Modality tokens Audio No No No No Audio No Audio and image
latency_ttft Yes Yes Yes Yes No No Yes Yes
api_host_type, api_host Yes Yes Yes Yes Opt-in Yes Yes Opt-in
Real tool outcome No No No No Yes Yes Yes Yes
thread_id No No No No No Yes No Yes
agent_name, workflow_name No No No No No No No Yes

The notes that matter most when you read these values:

  • Tool outcome: the four wrapped clients see the model request a tool, but your code runs it, so tool status is always unknown there.
  • Endpoint on Vercel AI SDK: api_host_type is unknown unless you pass apiBaseURL.
  • Endpoint on Mastra: Mastra does not report the endpoint, so every event reports unknown unless you add it yourself with a span output processor. Here, unknown means "not reported", not "an unusual endpoint".
  • Turn grouping: LlamaIndex exposes no turn identity, and Mastra records a workflow and the agents it calls as separate traces. Supply your own turn ID to group them into one run_id.
  • Absent cache writes: OpenAI, Google GenAI, and Cohere have no cache creation billing, so the field is absent, which is not the same as 0.
  • Missing request settings: Anthropic has no frequency or presence penalty, and LlamaIndex reports whatever the LLM instance exposes.

Changes in Schema Version 2

If you built queries or exports on an earlier version of the SDK, update them for these changes:

Earlier Field Schema 2 Field Reason
tools_used tools_requested A wrapped client sees the model request a tool, not run it
tool_call_count tool_request_count Same reason, and it now counts per generation, not per turn
cost_cached (deleted) cost_cache_read and cost_cache_saved cost_cached was never populated
api_base_url (deleted) api_host and api_host_type A raw URL can carry API keys and deployment IDs

Fix any query that reads cost_cached

A cache savings calculation of the form fullCost - cost_cached now subtracts nothing and reports 100% cache savings. Use cost_cache_read or cost_cache_saved instead.

Expect a visible step change on the day you upgrade. Placeholder interaction rows for turns without a generation are gone, so prompt counts drop, cost per prompt rises, model share shifts, and latency percentiles change. Row volume rises on framework adapters, because a turn now emits one event per generation. The tool and feedback events also gained the full envelope in this version.

Related Resources

For the settings that shape these events, such as observabilityLevel, tags, and costModel, see AI SDK Configuration Reference.

Was this page helpful?
Reach out to us for any other questions.
Helpful?

Looking For More Help?