The Cloudflare gateway adapter maps a fixed set of usage_metadata keys and hardcodes three extras keys, so any field the gateway sends that we don't map is dropped with no error and nothing in extras. That breaks the drift contract the other adapters hold.
Surveying every usage_metadata key across all 14 captured fixtures shows two live examples already:
| key |
fixtures |
mapped? |
in extras? |
input_tokens / output_tokens / total_tokens |
9 |
yes |
— |
input_cached_tokens |
8 |
yes |
— |
neurons |
4 |
no |
no |
input_cache_creation_tokens |
3 |
yes |
— |
reasoningTokens |
1 |
yes |
— |
input_text_tokens |
1 |
no |
no |
extras is currently {cached, step, log_id} — a hardcoded three, none of them from usage_metadata.
This is the same hole ancorcruz raised on the Databricks gateway adapter in #14 ("the only adapter in the repo with no drift sweep"), sitting in the Cloudflare one. openai_native, mistral_native, bedrock_converse and bedrock_invoke all sweep unrecognized usage keys into extras; these two gateway adapters don't.
Why it matters: neurons is Cloudflare's own compute unit and may become billable; input_text_tokens suggests a modality split we don't model. Either could turn into a real metric, and today it would vanish silently rather than surfacing for follow-up — which is exactly what the drift contract exists to prevent. No current billing impact: neither field is priced.
Suggested fix: sweep unmapped usage_metadata keys into extras under a dotted prefix (usage_metadata.neurons), mirroring what _MAPPED_DETAIL_FIELDS does in adapters/openai_native.py, and add a drift test alongside test_drift.py. Do it in both repos in the same PR pair, per CONTRIBUTING.
Deliberately split out of the Cloudflare connector PR (#13 / getlago/lago-agent-sdk-js#28) to keep that one to review feedback and money paths. Found while fixing the cache-key casing in that PR.
The Cloudflare gateway adapter maps a fixed set of
usage_metadatakeys and hardcodes threeextraskeys, so any field the gateway sends that we don't map is dropped with no error and nothing inextras. That breaks the drift contract the other adapters hold.Surveying every
usage_metadatakey across all 14 captured fixtures shows two live examples already:extras?input_tokens/output_tokens/total_tokensinput_cached_tokensneuronsinput_cache_creation_tokensreasoningTokensinput_text_tokensextrasis currently{cached, step, log_id}— a hardcoded three, none of them fromusage_metadata.This is the same hole
ancorcruzraised on the Databricks gateway adapter in #14 ("the only adapter in the repo with no drift sweep"), sitting in the Cloudflare one.openai_native,mistral_native,bedrock_converseandbedrock_invokeall sweep unrecognized usage keys intoextras; these two gateway adapters don't.Why it matters:
neuronsis Cloudflare's own compute unit and may become billable;input_text_tokenssuggests a modality split we don't model. Either could turn into a real metric, and today it would vanish silently rather than surfacing for follow-up — which is exactly what the drift contract exists to prevent. No current billing impact: neither field is priced.Suggested fix: sweep unmapped
usage_metadatakeys intoextrasunder a dotted prefix (usage_metadata.neurons), mirroring what_MAPPED_DETAIL_FIELDSdoes inadapters/openai_native.py, and add a drift test alongsidetest_drift.py. Do it in both repos in the same PR pair, per CONTRIBUTING.Deliberately split out of the Cloudflare connector PR (#13 / getlago/lago-agent-sdk-js#28) to keep that one to review feedback and money paths. Found while fixing the cache-key casing in that PR.