@@ -49,7 +49,7 @@ def fake_completion_cost(completion_response):
49
49
@pytest .mark .allow_call_model_methods
50
50
@pytest .mark .asyncio
51
51
async def test_cost_none_when_track_cost_disabled (monkeypatch ):
52
- """Test that cost is None when track_cost=False (default )."""
52
+ """Test that cost is None when track_cost is not set (defaults to None/False )."""
53
53
54
54
async def fake_acompletion (model , messages = None , ** kwargs ):
55
55
msg = Message (role = "assistant" , content = "Test response" )
@@ -61,13 +61,13 @@ async def fake_acompletion(model, messages=None, **kwargs):
61
61
return response
62
62
63
63
monkeypatch .setattr (litellm , "acompletion" , fake_acompletion )
64
- # Note: completion_cost should not be called when track_cost=False
64
+ # Note: completion_cost should not be called when track_cost is None (default)
65
65
66
66
model = LitellmModel (model = "test-model" , api_key = "test-key" )
67
67
result = await model .get_response (
68
68
system_instructions = None ,
69
69
input = [],
70
- model_settings = ModelSettings (track_cost = False ), # Disabled (default )
70
+ model_settings = ModelSettings (), # track_cost defaults to None (disabled )
71
71
tools = [],
72
72
output_schema = None ,
73
73
handoffs = [],
@@ -192,3 +192,29 @@ def fake_completion_cost(completion_response):
192
192
assert result .usage .total_tokens == 150
193
193
assert result .usage .cost == 0.001
194
194
assert result .usage .requests == 1
195
+
196
+
197
+ def test_track_cost_sticky_through_resolve ():
198
+ """Test that track_cost=True is not overwritten by resolve() with empty override."""
199
+ base = ModelSettings (track_cost = True , temperature = 0.7 )
200
+ override = ModelSettings (max_tokens = 100 ) # Only setting max_tokens, track_cost is None
201
+
202
+ resolved = base .resolve (override )
203
+
204
+ # track_cost should remain True because override's track_cost is None (not False)
205
+ assert resolved .track_cost is True
206
+ assert resolved .temperature == 0.7
207
+ assert resolved .max_tokens == 100
208
+
209
+
210
+ def test_track_cost_can_be_explicitly_disabled ():
211
+ """Test that track_cost=True can be explicitly overridden to False."""
212
+ base = ModelSettings (track_cost = True , temperature = 0.7 )
213
+ override = ModelSettings (track_cost = False , max_tokens = 100 )
214
+
215
+ resolved = base .resolve (override )
216
+
217
+ # track_cost should be False because override explicitly set it to False
218
+ assert resolved .track_cost is False
219
+ assert resolved .temperature == 0.7
220
+ assert resolved .max_tokens == 100
0 commit comments