Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/python/tests/test_cost_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Pydantic validates Decimal type — rejects float
- None means unknown (not zero)
- Decimal("0") means explicitly free
- SessionStatus.estimated_cost is removed (was never populated)
- SessionStatus.estimated_cost is deprecated (was never populated)
"""

from decimal import Decimal
Expand Down
36 changes: 36 additions & 0 deletions crates/amplifier-core/src/generated/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl From<crate::messages::Usage> for super::amplifier_module::Usage {
i32::MAX
})
}),
cost_usd: native.cost_usd.clone(),
}
}
}
Expand All @@ -181,6 +182,7 @@ impl From<super::amplifier_module::Usage> for crate::messages::Usage {
reasoning_tokens: proto.reasoning_tokens.map(i64::from),
cache_read_tokens: proto.cache_read_tokens.map(i64::from),
cache_write_tokens: proto.cache_creation_tokens.map(i64::from),
cost_usd: proto.cost_usd.clone(),
extensions: HashMap::new(),
}
}
Expand Down Expand Up @@ -1111,6 +1113,40 @@ mod tests {
);
}

/// Verify that cost_usd survives roundtrip (None and Some cases).
#[test]
fn usage_cost_usd_roundtrips_correctly() {
// Test Some case
let original_with_cost = crate::messages::Usage {
input_tokens: 100,
output_tokens: 50,
total_tokens: 150,
reasoning_tokens: None,
cache_read_tokens: None,
cache_write_tokens: None,
cost_usd: Some("0.123".to_string()),
extensions: HashMap::new(),
};
let proto: super::super::amplifier_module::Usage = original_with_cost.clone().into();
let restored: crate::messages::Usage = proto.into();
assert_eq!(original_with_cost.cost_usd, restored.cost_usd);

// Test None case
let original_without_cost = crate::messages::Usage {
input_tokens: 100,
output_tokens: 50,
total_tokens: 150,
reasoning_tokens: None,
cache_read_tokens: None,
cache_write_tokens: None,
cost_usd: None,
extensions: HashMap::new(),
};
let proto: super::super::amplifier_module::Usage = original_without_cost.clone().into();
let restored: crate::messages::Usage = proto.into();
assert_eq!(original_without_cost.cost_usd, restored.cost_usd);
}

// -- E-3: ModelInfo i64→i32 overflow clamps to i32::MAX --

#[test]
Expand Down
2 changes: 2 additions & 0 deletions crates/amplifier-core/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ pub struct Usage {
pub cache_read_tokens: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cache_write_tokens: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cost_usd: Option<String>,
#[serde(flatten)]
pub extensions: HashMap<String, Value>,
}
Expand Down
1 change: 1 addition & 0 deletions proto/amplifier_module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ message Usage {
optional int32 reasoning_tokens = 4;
optional int32 cache_read_tokens = 5;
optional int32 cache_creation_tokens = 6;
optional string cost_usd = 7;
}

message Degradation {
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading