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]

test(cost): add tier 1 gpt cache_read cases and recapture input_text usage shapes (#46623)

devin-ai-integration[bot]f08840579ebc
diff --git a/tests/integration/cost_calculation/cases/anthropic.py b/tests/integration/cost_calculation/cases/anthropic.py
index ca97898bea9..4d0987ec1f9 100644
--- a/tests/integration/cost_calculation/cases/anthropic.py
+++ b/tests/integration/cost_calculation/cases/anthropic.py
@@ -4062,7 +4062,16 @@ CLAUDE_OPUS_5_5_INPUT_TEXT: Final = CostTrackingTestCase(
"content": [{"type": "text", "text": "Hello."}],
"stop_reason": "end_turn",
"stop_sequence": None,
- "usage": {"input_tokens": 1840, "output_tokens": 412},
+ "usage": {
+ "input_tokens": 1840,
+ "cache_creation_input_tokens": 0,
+ "cache_read_input_tokens": 0,
+ "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0},
+ "output_tokens": 412,
+ "output_tokens_details": {"thinking_tokens": 0},
+ "service_tier": "standard",
+ "inference_geo": "global",
+ },
},
),
expected=ExactExpected(
diff --git a/tests/integration/cost_calculation/cases/azure.py b/tests/integration/cost_calculation/cases/azure.py
index 173cf0626c1..5b4210f3869 100644
--- a/tests/integration/cost_calculation/cases/azure.py
+++ b/tests/integration/cost_calculation/cases/azure.py
@@ -5574,6 +5574,270 @@ AZURE_GPT_6_LUNA_TOOL_CALL: Final = CostTrackingTestCase(
),
)
+AZURE_GPT_6_1_SOL_CACHE_READ: Final = AZURE_GPT_5_6_CACHE_READ.model_copy(
+ update={
+ "name": "azure/gpt-6.1-sol-cache_read",
+ "model": "azure/gpt-6.1-sol",
+ "request": {
+ "model": "$MODEL",
+ "messages": [
+ {
+ "role": "system",
+ "content": [
+ {
+ "type": "text",
+ "text": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",
+ }
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "c3a6bc6e3512 summarize the attached material in one line and name the city weather",
+ }
+ ],
+ },
+ ],
+ "stream": False,
+ "allowed_openai_params": [],
+ },
+ "response": JsonResponse(
+ content_type="application/json",
+ body={
+ "choices": [
+ {
+ "content_filter_results": _GPT_6_CONTENT_FILTER_RESULTS,
+ "finish_reason": "stop",
+ "index": 0,
+ "logprobs": None,
+ "message": {
+ "annotations": [],
+ "content": "scripted answer c3a6bc6e3512",
+ "refusal": None,
+ "role": "assistant",
+ },
+ }
+ ],
+ "created": 1792042948,
+ "id": "chatcmpl-$REQUEST_ID",
+ "model": "gpt-6.1-sol-2026-09-29",
+ "object": "chat.completion",
+ "prompt_filter_results": _GPT_6_PROMPT_FILTER_RESULTS,
+ "routing": {"serving_pipereplica": "d20260929042311-28ecf0ee-prefill-r1-dp0-prefill"},
+ "service_tier": "default",
+ "system_fingerprint": None,
+ "usage": {
+ "completion_tokens": 380,
+ "completion_tokens_details": {
+ "accepted_prediction_tokens": 0,
+ "audio_tokens": 0,
+ "reasoning_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ "latency_checkpoint": {
+ "engine_tbt_ms": 23,
+ "engine_ttft_ms": 484,
+ "engine_ttlt_ms": 999,
+ "pre_inference_ms": 151,
+ "service_tbt_ms": 25,
+ "service_ttft_ms": 1085,
+ "service_ttlt_ms": 1610,
+ "user_visible_ttft_ms": 934,
+ },
+ "prompt_tokens": 12928,
+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 12288},
+ "total_tokens": 13308,
+ },
+ },
+ ),
+ "expected": ExactExpected(
+ spend=0.00904512,
+ input_cost=0.00448512,
+ output_cost=0.00456,
+ prompt_tokens=12928,
+ completion_tokens=380,
+ ),
+ }
+)
+
+AZURE_GPT_6_LUNA_CACHE_READ: Final = AZURE_GPT_5_6_CACHE_READ.model_copy(
+ update={
+ "name": "azure/gpt-6-luna-cache_read",
+ "model": "azure/gpt-6-luna",
+ "request": {
+ "model": "$MODEL",
+ "messages": [
+ {
+ "role": "system",
+ "content": [
+ {
+ "type": "text",
+ "text": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",
+ }
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "67d7b9931ce9 summarize the attached material in one line and name the city weather",
+ }
+ ],
+ },
+ ],
+ "stream": False,
+ "allowed_openai_params": [],
+ },
+ "response": JsonResponse(
+ content_type="application/json",
+ body={
+ "choices": [
+ {
+ "content_filter_results": _GPT_6_CONTENT_FILTER_RESULTS,
+ "finish_reason": "stop",
+ "index": 0,
+ "logprobs": None,
+ "message": {
+ "annotations": [],
+ "content": "scripted answer 67d7b9931ce9",
+ "refusal": None,
+ "role": "assistant",
+ },
+ }
+ ],
+ "created": 1792042952,
+ "id": "chatcmpl-$REQUEST_ID",
+ "model": "gpt-6-luna-2026-09-22",
+ "object": "chat.completion",
+ "prompt_filter_results": _GPT_6_PROMPT_FILTER_RESULTS,
+ "routing": {"serving_pipereplica": "d20260919024711-372ad1ad-prefill-r2-dp0-prefill"},
+ "service_tier": "default",
+ "system_fingerprint": None,
+ "usage": {
+ "completion_tokens": 380,
+ "completion_tokens_details": {
+ "accepted_prediction_tokens": 0,
+ "audio_tokens": 0,
+ "reasoning_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ "latency_checkpoint": {
+ "engine_tbt_ms": 7,
+ "engine_ttft_ms": 110,
+ "engine_ttlt_ms": 706,
+ "pre_inference_ms": 254,
+ "service_tbt_ms": 7,
+ "service_ttft_ms": 647,
+ "service_ttlt_ms": 1238,
+ "user_visible_ttft_ms": 393,
+ },
+ "prompt_tokens": 12928,
+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 12288},
+ "total_tokens": 13308,
+ },
+ },
+ ),
+ "expected": ExactExpected(
+ spend=0.000489944,
+ input_cost=0.000242944,
+ output_cost=0.000247,
+ prompt_tokens=12928,
+ completion_tokens=380,
+ ),
+ }
+)
+
+AZURE_GPT_6_ASTRA_CACHE_READ: Final = AZURE_GPT_5_6_CACHE_READ.model_copy(
+ update={
+ "name": "azure/gpt-6-astra-cache_read",
+ "model": "azure/gpt-6-astra",
+ "request": {
+ "model": "$MODEL",
+ "messages": [
+ {
+ "role": "system",
+ "content": [
+ {
+ "type": "text",
+ "text": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",
+ }
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "84f5db610aa3 summarize the attached material in one line and name the city weather",
+ }
+ ],
+ },
+ ],
+ "stream": False,
+ "allowed_openai_params": [],
+ },
+ "response": JsonResponse(
+ content_type="application/json",
+ body={
+ "choices": [
+ {
+ "content_filter_results": _GPT_6_CONTENT_FILTER_RESULTS,
+ "finish_reason": "stop",
+ "index": 0,
+ "logprobs": None,
+ "message": {
+ "annotations": [],
+ "content": "scripted answer 84f5db610aa3",
+ "refusal": None,
+ "role": "assistant",
+ },
+ }
+ ],
+ "created": 1792042958,
+ "id": "chatcmpl-$REQUEST_ID",
+ "model": "gpt-6-astra-2026-09-03",
+ "object": "chat.completion",
+ "prompt_filter_results": _GPT_6_PROMPT_FILTER_RESULTS,
+ "routing": {"serving_pipereplica": "d20260930073654-95d85d6a-prefill-r29-dp0-prefill"},
+ "service_tier": "default",
+ "system_fingerprint": None,
+ "usage": {
+ "completion_tokens": 380,
+ "completion_tokens_details": {
+ "accepted_prediction_tokens": 0,
+ "audio_tokens": 0,
+ "reasoning_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ "latency_checkpoint": {
+ "engine_tbt_ms": 25,
+ "engine_ttft_ms": 697,
+ "engine_ttlt_ms": 1373,
+ "pre_inference_ms": 142,
+ "service_tbt_ms": 26,
+ "service_ttft_ms": 1289,
+ "service_ttlt_ms": 1956,
+ "user_visible_ttft_ms": 1147,
+ },
+ "prompt_tokens": 12928,
+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 12288},
+ "total_tokens": 13308,
+ },
+ },
+ ),
+ "expected": ExactExpected(
+ spend=0.04711,
+ input_cost=0.02336,
+ output_cost=0.02375,
+ prompt_tokens=12928,
+ completion_tokens=380,
+ ),
+ }
+)
+
AZURE_GPT_6_SOL_MESSAGES_BRIDGED_JSON: Final = AZURE_GPT_6_SOL_INPUT_TEXT.model_copy(
update={
"name": "azure-gpt-6-sol-messages_bridged_json",
@@ -5947,6 +6211,9 @@ CASES: Final[tuple[CostTrackingTestCase, ...]] = (
AZURE_GPT_6_SOL_INPUT_TEXT_ROLLUPS,
AZURE_GPT_6_SOL_TOOL_CALL,
AZURE_GPT_6_LUNA_TOOL_CALL,
+ AZURE_GPT_6_1_SOL_CACHE_READ,
+ AZURE_GPT_6_LUNA_CACHE_READ,
+ AZURE_GPT_6_ASTRA_CACHE_READ,
)
PARITY: Final[tuple[StreamParityTestCase, ...]] = (
diff --git a/tests/integration/cost_calculation/cases/openai.py b/tests/integration/cost_calculation/cases/openai.py
index eb7897ba259..e50a82ceaa5 100644
--- a/tests/integration/cost_calculation/cases/openai.py
+++ b/tests/integration/cost_calculation/cases/openai.py
@@ -8038,7 +8038,18 @@ GPT_6_1_SOL_INPUT_TEXT: Final = CostTrackingTestCase(
"created": 1,
"model": "gpt-6.1-sol",
"choices": [{"index": 0, "message": {"role": "assistant", "content": "Hello."}, "finish_reason": "stop"}],
- "usage": {"prompt_tokens": 1840, "completion_tokens": 412, "total_tokens": 2252},
+ "usage": {
+ "prompt_tokens": 1840,
+ "completion_tokens": 412,
+ "total_tokens": 2252,
+ "prompt_tokens_details": {"cached_tokens": 0, "cache_write_tokens": 0, "audio_tokens": 0},
+ "completion_tokens_details": {
+ "reasoning_tokens": 0,
+ "audio_tokens": 0,
+ "accepted_prediction_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ },
},
),
expected=ExactExpected(
@@ -8046,6 +8057,258 @@ GPT_6_1_SOL_INPUT_TEXT: Final = CostTrackingTestCase(
),
)
+GPT_6_1_SOL_CACHE_READ: Final = GPT_5_6_CACHE_READ.model_copy(
+ update={
+ "name": "gpt-6.1-sol-cache_read",
+ "model": "gpt-6.1-sol",
+ "request": {
+ "model": "$MODEL",
+ "messages": [
+ {
+ "role": "system",
+ "content": [
+ {
+ "type": "text",
+ "text": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",
+ }
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "b770f5df16a2 summarize the attached material in one line and name the city weather",
+ }
+ ],
+ },
+ ],
+ "stream": False,
+ "allowed_openai_params": [],
+ },
+ "response": JsonResponse(
+ content_type="application/json",
+ body={
+ "id": "chatcmpl-$REQUEST_ID",
+ "object": "chat.completion",
+ "created": 1792042876,
+ "model": "gpt-6.1-sol",
+ "choices": [
+ {
+ "index": 0,
+ "message": {
+ "role": "assistant",
+ "content": "scripted answer b770f5df16a2",
+ "refusal": None,
+ "annotations": [],
+ },
+ "finish_reason": "stop",
+ }
+ ],
+ "service_tier": "default",
+ "system_fingerprint": None,
+ "usage": {
+ "completion_tokens": 380,
+ "completion_tokens_details": {
+ "accepted_prediction_tokens": 0,
+ "audio_tokens": 0,
+ "reasoning_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ "latency_checkpoint": {
+ "engine_tbt_ms": 23,
+ "engine_ttft_ms": 484,
+ "engine_ttlt_ms": 999,
+ "pre_inference_ms": 151,
+ "service_tbt_ms": 25,
+ "service_ttft_ms": 1085,
+ "service_ttlt_ms": 1610,
+ "user_visible_ttft_ms": 934,
+ },
+ "prompt_tokens": 12928,
+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 12288},
+ "total_tokens": 13308,
+ },
+ },
+ ),
+ "expected": ExactExpected(
+ spend=0.0063088,
+ input_cost=0.0025088,
+ output_cost=0.0038,
+ prompt_tokens=12928,
+ completion_tokens=380,
+ ),
+ }
+)
+
+GPT_6_LUNA_CACHE_READ: Final = GPT_5_6_CACHE_READ.model_copy(
+ update={
+ "name": "gpt-6-luna-cache_read",
+ "model": "gpt-6-luna",
+ "request": {
+ "model": "$MODEL",
+ "messages": [
+ {
+ "role": "system",
+ "content": [
+ {
+ "type": "text",
+ "text": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",
+ }
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "a880e9da100c summarize the attached material in one line and name the city weather",
+ }
+ ],
+ },
+ ],
+ "stream": False,
+ "allowed_openai_params": [],
+ },
+ "response": JsonResponse(
+ content_type="application/json",
+ body={
+ "id": "chatcmpl-$REQUEST_ID",
+ "object": "chat.completion",
+ "created": 1792042880,
+ "model": "gpt-6-luna",
+ "choices": [
+ {
+ "index": 0,
+ "message": {
+ "role": "assistant",
+ "content": "scripted answer a880e9da100c",
+ "refusal": None,
+ "annotations": [],
+ },
+ "finish_reason": "stop",
+ }
+ ],
+ "service_tier": "default",
+ "system_fingerprint": None,
+ "usage": {
+ "completion_tokens": 380,
+ "completion_tokens_details": {
+ "accepted_prediction_tokens": 0,
+ "audio_tokens": 0,
+ "reasoning_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ "latency_checkpoint": {
+ "engine_tbt_ms": 7,
+ "engine_ttft_ms": 110,
+ "engine_ttlt_ms": 706,
+ "pre_inference_ms": 254,
+ "service_tbt_ms": 7,
+ "service_ttft_ms": 647,
+ "service_ttlt_ms": 1238,
+ "user_visible_ttft_ms": 393,
+ },
+ "prompt_tokens": 12928,
+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 12288},
+ "total_tokens": 13308,
+ },
+ },
+ ),
+ "expected": ExactExpected(
+ spend=0.00037688,
+ input_cost=0.00018688,
+ output_cost=0.00019,
+ prompt_tokens=12928,
+ completion_tokens=380,
+ ),
+ }
+)
+
+GPT_6_ASTRA_CACHE_READ: Final = GPT_5_6_CACHE_READ.model_copy(
+ update={
+ "name": "gpt-6-astra-cache_read",
+ "model": "gpt-6-astra",
+ "request": {
+ "model": "$MODEL",
+ "messages": [
+ {
+ "role": "system",
+ "content": [
+ {
+ "type": "text",
+ "text": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",
+ }
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "text",
+ "text": "d45eefac915d summarize the attached material in one line and name the city weather",
+ }
+ ],
+ },
+ ],
+ "stream": False,
+ "allowed_openai_params": [],
+ },
+ "response": JsonResponse(
+ content_type="application/json",
+ body={
+ "id": "chatcmpl-$REQUEST_ID",
+ "object": "chat.completion",
+ "created": 1792042883,
+ "model": "gpt-6-astra",
+ "choices": [
+ {
+ "index": 0,
+ "message": {
+ "role": "assistant",
+ "content": "scripted answer d45eefac915d",
+ "refusal": None,
+ "annotations": [],
+ },
+ "finish_reason": "stop",
+ }
+ ],
+ "service_tier": "default",
+ "system_fingerprint": None,
+ "usage": {
+ "completion_tokens": 380,
+ "completion_tokens_details": {
+ "accepted_prediction_tokens": 0,
+ "audio_tokens": 0,
+ "reasoning_tokens": 0,
+ "rejected_prediction_tokens": 0,
+ },
+ "latency_checkpoint": {
+ "engine_tbt_ms": 25,
+ "engine_ttft_ms": 697,
+ "engine_ttlt_ms": 1373,
+ "pre_inference_ms": 142,
+ "service_tbt_ms": 26,
+ "service_ttft_ms": 1289,
+ "service_ttlt_ms": 1956,
+ "user_visible_ttft_ms": 1147,
+ },
+ "prompt_tokens": 12928,
+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 12288},
+ "total_tokens": 13308,
+ },
+ },
+ ),
+ "expected": ExactExpected(
+ spend=0.0452256,
+ input_cost=0.0224256,
+ output_cost=0.0228,
+ prompt_tokens=12928,
+ completion_tokens=380,
+ ),
+ }
+)
+
_OPENAI_GPT_6_LUNA_DECISIONS_INPUT_TOKENS: Final = 367
_OPENAI_GPT_6_LUNA_DECISIONS_OUTPUT_TOKENS: Final = 3
@@ -11043,6 +11306,9 @@ CASES: Final[tuple[CostTrackingTestCase, ...]] = (
GPT_6_1_SOL_STREAM_NO_USAGE,
GPT_6_SOL_UPSTREAM_404_ZERO_SPEND,
GPT_6_SOL_INPUT_TEXT_ROLLUPS,
+ GPT_6_1_SOL_CACHE_READ,
+ GPT_6_LUNA_CACHE_READ,
+ GPT_6_ASTRA_CACHE_READ,
)
PARITY: Final[tuple[StreamParityTestCase, ...]] = (
diff --git a/tests/integration/cost_calculation/cost_map.py b/tests/integration/cost_calculation/cost_map.py
index eb56831758d..2a036ff23d2 100644
--- a/tests/integration/cost_calculation/cost_map.py
+++ b/tests/integration/cost_calculation/cost_map.py
@@ -890,6 +890,8 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = {
"input_cost_per_token_priority": 4e-06,
"output_cost_per_token_flex": 5e-06,
"input_cost_per_token_flex": 1e-06,
+ "cache_creation_input_token_cost": 2.5e-06,
+ "cache_creation_input_token_cost_above_272k_tokens": 5e-06,
"litellm_provider": "openai",
"mode": "chat",
"input_cost_per_token": 2e-06,
@@ -1071,6 +1073,8 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = {
},
"gpt-6-astra": {
"cache_read_input_token_cost": 1.2e-06,
+ "cache_creation_input_token_cost": 1.5e-05,
+ "cache_creation_input_token_cost_above_272k_tokens": 3e-05,
"input_cost_per_token": 1.2e-05,
"input_cost_per_token_flex": 6e-06,
"input_cost_per_token_priority": 2.4e-05,
@@ -1116,6 +1120,8 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = {
},
"azure/gpt-6-luna": {
"cache_read_input_token_cost": 1.3e-08,
+ "cache_creation_input_token_cost": 1.625e-07,
+ "cache_creation_input_token_cost_above_272k_tokens": 3.25e-07,
"input_cost_per_token": 1.3e-07,
"input_cost_per_token_flex": 6.5e-08,
"input_cost_per_token_priority": 2.6e-07,
@@ -1139,6 +1145,8 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = {
},
"azure/gpt-6-astra": {
"cache_read_input_token_cost": 1.25e-06,
+ "cache_creation_input_token_cost": 1.5625e-05,
+ "cache_creation_input_token_cost_above_272k_tokens": 3.125e-05,
"input_cost_per_token": 1.25e-05,
"input_cost_per_token_flex": 6.25e-06,
"input_cost_per_token_priority": 2.5e-05,
@@ -1162,6 +1170,8 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = {
},
"azure/gpt-6.1-sol": {
"cache_read_input_token_cost": 2.4e-07,
+ "cache_creation_input_token_cost": 3e-06,
+ "cache_creation_input_token_cost_above_272k_tokens": 6e-06,
"input_cost_per_token": 2.4e-06,
"input_cost_per_token_flex": 1.2e-06,
"input_cost_per_token_priority": 4.8e-06,