@@ -282,6 +282,74 @@ def _failing_fetch(*args, **kwargs):
282282 assert info ["input_cost_per_token" ] == 0.5 / manager .DEFAULT_TOKEN_PRICE_RATIO
283283
284284
285+ def test_pricing_normalization_detects_token_format (tmp_path ):
286+ """Test that pricing < 0.001 is treated as $/token, not $/M."""
287+ payload = {
288+ "data" : [
289+ {
290+ "id" : "demo/model" ,
291+ "context_length" : 2048 ,
292+ # Pricing in $/token format (like synthetic provider)
293+ "pricing" : {"prompt" : "0.00000055" , "completion" : "0.00000219" },
294+ }
295+ ]
296+ }
297+
298+ config = {
299+ "demo" : {
300+ "api_base" : "https://example.com/v1" ,
301+ "requires_api_key" : False ,
302+ }
303+ }
304+
305+ manager = _make_manager (tmp_path , config )
306+ cache_file = manager ._get_cache_file ("demo" )
307+ cache_file .write_text (json .dumps (payload ))
308+ manager ._cache_loaded ["demo" ] = True
309+ manager ._provider_cache ["demo" ] = payload
310+
311+ info = manager .get_model_info ("demo/demo/model" )
312+
313+ assert info ["max_input_tokens" ] == 2048
314+ # Values < 0.001 should NOT be divided (already in $/token format)
315+ assert info ["input_cost_per_token" ] == 0.00000055
316+ assert info ["output_cost_per_token" ] == 0.00000219
317+
318+
319+ def test_pricing_normalization_detects_million_format (tmp_path ):
320+ """Test that pricing >= 0.001 is treated as $/M and converted to $/token."""
321+ payload = {
322+ "data" : [
323+ {
324+ "id" : "demo/model" ,
325+ "context_length" : 2048 ,
326+ # Pricing in $/M format (like some providers)
327+ "pricing" : {"prompt" : "1.0" , "completion" : "2.0" },
328+ }
329+ ]
330+ }
331+
332+ config = {
333+ "demo" : {
334+ "api_base" : "https://example.com/v1" ,
335+ "requires_api_key" : False ,
336+ }
337+ }
338+
339+ manager = _make_manager (tmp_path , config )
340+ cache_file = manager ._get_cache_file ("demo" )
341+ cache_file .write_text (json .dumps (payload ))
342+ manager ._cache_loaded ["demo" ] = True
343+ manager ._provider_cache ["demo" ] = payload
344+
345+ info = manager .get_model_info ("demo/demo/model" )
346+
347+ assert info ["max_input_tokens" ] == 2048
348+ # Values >= 0.001 should be divided by 1000000 (convert $/M to $/token)
349+ assert info ["input_cost_per_token" ] == 1.0 / manager .DEFAULT_TOKEN_PRICE_RATIO
350+ assert info ["output_cost_per_token" ] == 2.0 / manager .DEFAULT_TOKEN_PRICE_RATIO
351+
352+
285353def test_model_info_manager_delegates_to_provider (monkeypatch , tmp_path ):
286354 monkeypatch .setattr (
287355 "aider.models.litellm" ,
0 commit comments