Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

ci(cost map): classify token_count_model as an object key in the schema generator (#47057)

Mateo Wang6e191a58f178
diff --git a/ci_cd/generate_model_prices_schema.py b/ci_cd/generate_model_prices_schema.py
index e429aae36b9..359df8e6e32 100644
--- a/ci_cd/generate_model_prices_schema.py
+++ b/ci_cd/generate_model_prices_schema.py
@@ -19,6 +19,7 @@ NONNEG_NUMBER: JsonSchema = {"type": "number", "minimum": 0}
NONNEG_INTEGER: JsonSchema = {"type": "integer", "minimum": 0}
BOOLEAN: JsonSchema = {"type": "boolean"}
STRING: JsonSchema = {"type": "string"}
+NON_BLANK_STRING: Final[JsonSchema] = {"type": "string", "pattern": r"\S"}
TIME_WINDOW: Final[JsonSchema] = {"type": "string", "pattern": r"^([01]\d|2[0-3]):[0-5]\d-([01]\d|2[0-3]):[0-5]\d$"}
WEEKDAY_PATTERN: Final = (
r"(?i)^(mon|monday|tue|tues|tuesday|wed|wednesday|thu|thur|thurs|thursday|fri|friday|sat|saturday|sun|sunday)$"
@@ -103,6 +104,16 @@ OBJECT_KEYS: dict[str, JsonSchema] = {
"type": "object",
"description": "Provider-internal routing hints (e.g. bedrock_invocation_schema).",
},
+ "token_count_model": {
+ "type": "object",
+ "required": ["model"],
+ "additionalProperties": False,
+ "properties": {
+ "model": NON_BLANK_STRING,
+ "region": NON_BLANK_STRING,
+ },
+ "description": "Model that counts tokens for this one, and the AWS region its count API runs in.",
+ },
}
ARRAY_KEYS: dict[str, JsonSchema] = {
@@ -287,11 +298,6 @@ def string_key_schemas(modes: tuple) -> dict[str, JsonSchema]:
"enum": ["none", "minimal", "low", "medium", "high", "xhigh"],
},
"comment": STRING,
- "token_count_fallback_model": {
- "type": "string",
- "minLength": 1,
- "description": "Model that counts tokens for this one when the provider cannot count it.",
- },
"audio_transcription_config": STRING,
"vertex_ai_audio_api": {
"type": "string",
diff --git a/tests/unit/test_model_prices_schema.py b/tests/unit/test_model_prices_schema.py
index ea484c4a2f4..aa171ed7a29 100644
--- a/tests/unit/test_model_prices_schema.py
+++ b/tests/unit/test_model_prices_schema.py
@@ -304,16 +304,23 @@ TOKEN_COUNT_ENTRY: Final = MappingProxyType(
"litellm_provider": "bedrock_converse",
"mode": "chat",
"token_count_framing": 78,
- "token_count_fallback_model": "us.anthropic.claude-opus-5-5",
+ "token_count_model": {"model": "us.anthropic.claude-opus-5-5", "region": "us-east-1"},
}
)
[email protected]("framing", [0, 78])
-def test_generator_classifies_token_count_settings(framing: int):
+ "setting",
+ [
+ {"token_count_framing": 0},
+ {"token_count_framing": 78},
+ {"token_count_model": {"model": "us.anthropic.claude-opus-5-5"}},
+ ],
+)
+def test_generator_classifies_token_count_settings(setting: dict):
generator = load_generator()
schema = json.loads(generator.render(generator.build_schema({"some-model": dict(TOKEN_COUNT_ENTRY)})))
- assert build_validator(schema).is_valid({"some-model": {**TOKEN_COUNT_ENTRY, "token_count_framing": framing}})
+ assert build_validator(schema).is_valid({"some-model": {**TOKEN_COUNT_ENTRY, **setting}})
@pytest.mark.parametrize(
@@ -322,8 +329,14 @@ def test_generator_classifies_token_count_settings(framing: int):
{"token_count_framing": -1},
{"token_count_framing": "78"},
{"token_count_framing": 1.5},
- {"token_count_fallback_model": ""},
- {"token_count_fallback_model": 5},
+ {"token_count_model": {"model": ""}},
+ {"token_count_model": {"model": " "}},
+ {"token_count_model": {"model": "us.anthropic.claude-opus-5-5", "region": ""}},
+ {"token_count_model": {"model": "us.anthropic.claude-opus-5-5", "region": " "}},
+ {"token_count_model": {"model": "us.anthropic.claude-opus-5-5", "region": 5}},
+ {"token_count_model": {"region": "us-east-1"}},
+ {"token_count_model": "us.anthropic.claude-opus-5-5"},
+ {"token_count_model": {"model": "us.anthropic.claude-opus-5-5", "zone": "us-east-1"}},
],
)
def test_generated_token_count_schema_rejects_malformed_settings(setting: dict):