docs: document and stabilize token/cost field semantics#330
docs: document and stabilize token/cost field semantics#330zhongxuanwang-nv wants to merge 1 commit into
Conversation
Add a canonical Token and Cost Field Semantics section to the provider response codecs page: a Usage/CostEstimate field reference, the per-provider token normalization table, granularity (per-call values vs the per-trajectory final_metrics aggregate), an exporter field-mapping table (ATOF/ATIF/OpenInference/OpenTelemetry), and a stability contract. Add brief field pointers and back-links on the OpenTelemetry, OpenInference, and ATIF exporter pages. Lock the contract with characterization tests: the OpenTelemetry LLM span emits cost only (no token attributes), Usage ignores unmodeled provider subfields, and OpenAIChatCodec drops completion_tokens_details. No runtime behavior change. Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (7)
📜 Recent review details⏰ Context from checks skipped due to timeout. (9)
🧰 Additional context used📓 Path-based instructions (25){docs/**,README.md,CONTRIBUTING.md}📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
{docs/**,README.md,CONTRIBUTING.md,**/*.md}📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
{docs/**,README.md}📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
{docs/**,examples/**,README.md}📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
{docs/**,README.md,**/Cargo.toml,**/package.json,**/*.md}📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
**/*.{md,mdx,py,sh,yaml,yml,toml,json}📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)
Files:
**/*.mdx📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)
Files:
**/*.{html,md,mdx}📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
docs/**/*.{md,mdx}📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
docs/**📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
**⚙️ CodeRabbit configuration file
Files:
{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}⚙️ CodeRabbit configuration file
Files:
**/*.rs📄 CodeRabbit inference engine (.agents/skills/add-binding-feature/SKILL.md)
Files:
{crates/adaptive/**/*.rs,**/*test*.{rs,py,go,ts,js},**/*adaptive*test*.{rs,py,go,ts,js},docs/plugins/adaptive/**}📄 CodeRabbit inference engine (.agents/skills/maintain-optimizer/SKILL.md)
Files:
**/{Cargo.toml,**/*.rs}📄 CodeRabbit inference engine (.agents/skills/maintain-packaging/SKILL.md)
Files:
**/*.{h,hpp,c,cpp,rs}📄 CodeRabbit inference engine (.agents/skills/maintain-packaging/SKILL.md)
Files:
{crates/core,crates/adaptive}/**/*📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)
Files:
**/*.{rs,toml}📄 CodeRabbit inference engine (.agents/skills/rename-surfaces/SKILL.md)
Files:
crates/core/**/*.rs📄 CodeRabbit inference engine (.agents/skills/test-go-binding/SKILL.md)
Files:
crates/{core,adaptive}/**📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
Files:
**/*.{rs,py,js,ts,tsx,jsx,go,sh,toml,yaml,yml,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{rs,py,go,js,ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
crates/**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
crates/{core,adaptive}/**/*.rs⚙️ CodeRabbit configuration file
Files:
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}⚙️ CodeRabbit configuration file
Files:
🔇 Additional comments (7)
WalkthroughAdds three unit tests validating codec behavior (dropping unmodeled ChangesToken and Cost Field Semantics: tests and docs
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
willkill07
left a comment
There was a problem hiding this comment.
Approving from dev perspective
Overview
Document and stabilize NeMo Relay's LLM token and cost field semantics. This freezes the current behavior as a documented contract and locks it with characterization tests. There is no runtime behavior change. The branch is merged with current
main, so the docs and tests reflect #304 (prefer normalized exporter fallbacks) and #305 (sharednemo_relay_typesDTO crate).Details
Adds a canonical Token and Cost Field Semantics section to
docs/integrate-into-frameworks/provider-response-codecs.mdx:UsageandCostEstimatefield reference (names, units, optionality; optional fields can also be codec-computed or pricing-synthesized).Usage).userstart step (no metrics) and anagentend step that carries metrics;final_metricsis the only aggregate (a per-trajectory sum of present step metrics, excluding embedded subagent trajectories).0.1/ATIF-v1.7/ pricing catalogversion: 1). The additive-compatibility promise is scoped to the serialized JSON/ATOF shapes; the RustUsage/CostEstimatestructs andCostSourceenum are exhaustive, so adding a field/variant is source-breaking for Rust consumers.Short field pointers + back-links were added to the OpenTelemetry, OpenInference, and ATIF exporter pages. Cost policy is stated once on the canonical page, per the runtime-contract docs convention.
Two characterization tests lock the freeze:
OtelEventProcessor, asserting the finished span carriesnemo_relay.llm.cost.{total,currency}and no token-count attribute in any namespace (token-containing orgen_ai.*keys fail).OpenAIChatCodecdropscompletion_tokens_details, andUsageignores unmodeled provider subfields (forward-compat: no serde catch-all).Existing tests already cover the remaining projections, per-provider mapping, reasoning-tokens-in-
api_specific, and the USD-only/currency-aware cost behavior.Testing: targeted
cargo teston the merged tree (the new/changed tests pass; perturbing the OTel exporter with anemo_relay.prompt_tokensattribute makes the span test fail as intended, then reverted),just docs-linkcheck(0 errors), andpre-commit(SPDX, markdown linkcheck, cargo fmt/clippy/check) all pass.Where should the reviewer start?
docs/integrate-into-frameworks/provider-response-codecs.mdx— the Token and Cost Field Semantics section (the exporter field-mapping table and the Stability subsection are the core contract). Thencrates/core/tests/unit/observability/otel_tests.rs::llm_end_emits_cost_only_no_token_or_gen_ai_attributes.Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit
Bug Fixes
Tests
Documentation