Documentation menu
DocsReference

Event Contract Reference

Product transport fields, SDK-local cost events, internal usage events, and protocol utilities.

View source

The public repository contains three related event shapes. They serve different stages of the data path and should not be treated as interchangeable.

ShapeProduced byPurposeSource
Product cloud eventTypeScript cloud adapter, Python client, or HTTP integrationsTransport product usage to /api/v1/eventscloud.ts
CostEvent / ProductUsageEventTypeScript metering and protocol consumersRepresent detailed local product cost and usagetypes.ts, protocol
InternalUsageEventCoding-agent collectors and internal integrationsTransport employee and team AI-tool usage to /api/v1/internal-usageprotocol

Product cloud event

This is the HTTP transport shape used by the maintained product SDKs.

FieldTypeMeaning
tsstringISO 8601 event time
sourcestring?Stable integration type; must be paired with externalId
externalIdstring?Stable source record ID; must be paired with source
providerstringProvider identifier such as openai, anthropic, or google-vertex
modelstringProvider model identifier
promptTokensnumberTotal input tokens
outputTokensnumberGenerated output tokens
totalTokensnumberCombined input and output token count
cacheReadTokensnumber?Input tokens served from provider cache
cacheWriteTokensnumber?Input tokens written to provider cache
costUsdnumberEvent cost in USD
latencyMsnumber?Provider latency in milliseconds
status"success" | "error"Provider-call outcome
featurestring?Product feature or request path
tenantIdstring?Paying customer or account
userIdstring?End user
agentIdstring?Agent identity
workflowIdstring?Workflow identity
runIdstring?One workflow or agent execution
stepIdstring?Step within an execution
toolNamestring?Tool used by an agent
retryCountnumber?Retry attempt number
outcomestring?Product or workflow result
metadataobjectStructured context and SDK metadata
prompt, outputstring?Optional samples when explicitly supplied and approved

The TypeScript cloud adapter maps local error, cache, prompt-version, session, environment, and legacy tags into metadata. The Python client adds metadata.sdk and metadata.sdkVersion.

When both source and externalId are present, retries are idempotent within a workspace. A duplicate is reported as deduplicated, is not written again, does not update product rollups or alerts, and does not consume another ingest event. Use a stable source configuration namespace when two installations of the same integration can emit the same upstream identifier.

Local CostEvent

@traice/sdk adapters receive the local CostEvent before cloud transport mapping.

Field groupFields
Identityid, timestamp
Providerprovider, model
UsageinputTokens, outputTokens, totalTokens, cacheReadTokens, cacheWriteTokens
CostinputCostUSD, outputCostUSD, totalCostUSD
RequestlatencyMs, status, errorMessage, cached
Product attributionfeature, tenantId, userId, sessionId, env
Workflow attributionagentId, workflowId, runId, stepId, toolName, retryCount, outcome
Prompt attributionpromptName, promptVersion, optional prompt, optional output
Additional contextmetadata, legacy tags

@traice/protocol exports a structurally similar ProductUsageEvent for consumers that need a shared public type without the SDK implementation.

Internal usage event

Internal usage describes employee and team AI-tool spend. It is not a product event.

Required fields:

FieldMeaning
sourceKeyStable source configuration identifier
sourceKindSource adapter or ingestion kind
toolTool name, such as claude-code or codex
categorycoding_agent, chat_agent, ide_assistant, or other
sourceEventIdStable retry-safe source event identifier
occurredAtISO 8601 event time

Optional identity and allocation fields:

Field groupFields
SourcesourceName, sourcePrincipal
EmployeeemployeeEmail, employeeName, employeeExternalId
TeamteamName, teamExternalId
Seat allocationseatMonthlyUsd
Providerprovider, model
ExecutionrunId, stepId
UsageinputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, totalTokens
CostcostUsd, costBasis
Resultstatus with success, error, or unknown; optional latencyMs
ContextJSON-safe metadata

Protocol utilities

Import these from @traice/protocol.

APIBehaviorSource
normalizeInternalUsageEventTrim identifiers, normalize the timestamp and token counts, derive total tokens, and default status to unknownindex.ts
assertValidInternalUsageEventRequire core source fields and a valid timestampindex.ts
redactMetadataConvert unknown values to JSON-safe values and redact secret-looking keys and credential patternsindex.ts
stableSourceEventIdJoin defined identifier parts with : for retry-safe source identityindex.ts

Public protocol types also include JsonPrimitive, JsonValue, JsonRecord, InternalUsageCategory, InternalUsageStatus, CollectorIdentity, and CollectorSource.