Skip to main content
Majordomo stores one row per LLM request in the llm_requests table. You can query this table directly for cost attribution, usage analysis, or debugging. This page is the complete column reference for llm_requests and the companion llm_requests_metadata_keys registry, plus SQL patterns to get you started.
Where data lives
  • The Majordomo gateway writes request rows immediately to its local database and uploads request/response bodies to your S3 or GCS bucket when cloud body storage is configured.
  • Majordomo’s cloud control plane ingests usage and metadata in batches and serves the dashboard and API.
  • If you query the data directly, connect to the same database that the dashboard reads from for consistent results.

llm_requests

One row is written per proxied request.
ColumnTypeDescription
iduuidUnique request identifier.
majordomo_api_key_iduuidThe Majordomo API key that authenticated the request.
provider_api_key_hashvarchar(64)Hash of the upstream provider Authorization header.
provider_api_key_aliasvarchar(255)Optional alias set via X-Majordomo-Provider-Alias.
providervarchar(100)Provider name: openai, anthropic, or gemini.
modelvarchar(100)Model name as reported or translated by Majordomo.
request_pathtextUpstream path (e.g., /v1/chat/completions).
request_methodtextHTTP method of the request.
requested_attimestamptzTimestamp when the request was received by the gateway.
responded_attimestamptzTimestamp when the response was fully sent to the caller.
response_time_msintWall-clock response time in milliseconds.
input_tokensintInput token count parsed from the provider response.
output_tokensintOutput token count parsed from the provider response.
cached_tokensintPrompt caching read tokens, when applicable.
cache_creation_tokensintTokens charged to create cache entries.
input_costnumeric(12,8)Calculated cost for input tokens.
output_costnumeric(12,8)Calculated cost for output tokens.
total_costnumeric(12,8)Sum of input, output, and cache costs.
status_codeintHTTP status code returned by the upstream provider.
error_messagetextTruncated error body when the status code is 400 or higher.
raw_metadatajsonbAll custom X-Majordomo-* headers (excluding reserved keys) stored without indexing.
indexed_metadatajsonbSubset of metadata keys copied here for fast @> queries (GIN-indexed).
request_bodytextLocal copy of the request body. Only populated when Postgres body storage is enabled.
response_bodytextLocal copy of the response body. Only populated when Postgres body storage is enabled.
body_s3_keytextObject key for the body when uploaded to S3 or GCS via cloud body storage.
model_alias_foundbooltrue if a pricing alias was resolved for the model name.
org_iduuidOwning organization, used for filtering and joins.
created_attimestamptzTimestamp when the row was created.
synced_to_butlerboolInternal sync flag: true once the row has been batched to Majordomo Cloud.
Indexes: composite index on (majordomo_api_key_id, requested_at DESC), and a GIN index on indexed_metadata.

llm_requests_metadata_keys

A per-API-key registry of every metadata key Majordomo has observed, along with its indexing state and usage statistics.
ColumnTypeDescription
majordomo_api_key_iduuidAPI key owner. Part of the primary key.
key_namevarchar(255)Stored key name with the X-Majordomo- prefix stripped. Part of the primary key.
display_namevarchar(255)Human-readable label shown in the dashboard UI.
key_typevarchar(50)Semantic type hint. Defaults to string.
is_requiredboolReserved for future validation.
is_activeboolWhen true, this key is copied into indexed_metadata on new requests.
activated_attimestamptzTimestamp when indexing was enabled for this key.
request_countbigintNumber of requests that have included this key.
last_seen_attimestamptzTimestamp of the most recent request carrying this key.
hll_statebyteaHyperLogLog sketch state used for cardinality estimation.
approx_cardinalityintApproximate number of unique values observed for this key.
hll_updated_attimestamptzTimestamp of the last HyperLogLog update.
created_attimestamptzTimestamp when this key was first recorded.
Index: is_active per API key for fast dashboard lookups.

Notes

The following reserved headers are never written to raw_metadata: X-Majordomo-Key, X-Majordomo-Provider, and X-Majordomo-Provider-Alias.
Storing request and response bodies in Postgres is disabled by default. For production deployments, use Cloud Body Storage to write bodies to S3 or GCS instead of your database.

SQL primer

For end-to-end examples, see Cost Attribution. A few quick patterns to get started:
-- Last 7 days by day
SELECT date_trunc('day', requested_at) AS day,
       COUNT(*) AS requests,
       SUM(total_cost) AS total_cost
FROM llm_requests
WHERE requested_at >= now() - interval '7 days'
GROUP BY 1
ORDER BY 1;
-- Filter by an indexed metadata key (fast)
SELECT COUNT(*), SUM(total_cost)
FROM llm_requests
WHERE indexed_metadata @> '{"Feature": "document-review"}';
-- Filter by a non-indexed key (works, slower)
SELECT COUNT(*), SUM(total_cost)
FROM llm_requests
WHERE raw_metadata->>'Team' = 'platform';
Queries against indexed_metadata use the GIN index and are significantly faster than scanning raw_metadata. Promote high-cardinality or frequently-filtered keys to indexed_metadata from the dashboard.