Skip to content

Cloudflare gateway adapter drops unmapped usage_metadata fields instead of surfacing them in extras #16

Description

@anassg-lago

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions