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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(cost): add xai grok-4.7, Bedrock runtime chat completions and Bedrock Mantle cost cases (#46154)
Kerry Lu5f74a79c750d
diff --git a/tests/integration/cost_calculation/cases/bedrock_chat_completions.py b/tests/integration/cost_calculation/cases/bedrock_chat_completions.pynew file mode 100644index 00000000000..d36084374ae--- /dev/null+++ b/tests/integration/cost_calculation/cases/bedrock_chat_completions.py@@ -0,0 +1,576 @@+"""Bedrock runtime /openai/v1/chat/completions cost tracking cases (xAI grok-4.7 and OpenAI gpt-6-sol on Bedrock), the rows LiteLLM routes to the OpenAI-compatible Bedrock endpoint instead of Converse."""++from __future__ import annotations++from typing import Final++from integration.cost_calculation.cases.openai import with_usage+from integration.cost_calculation.cost_tracking_case import (+ CostTrackingTestCase,+ Deployment,+ ExactExpected,+ JsonResponse,+ SseResponse,+)+from integration.cost_calculation.stream_parity.case import StreamParityTestCase, sse_frames+++BEDROCK_US_XAI_GROK_4_7_INPUT_TEXT: Final = CostTrackingTestCase(+ name="bedrock-us.xai.grok-4.7-input_text",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.xai.grok-4.7",+ deployment=Deployment(model="bedrock/us.xai.grok-4.7"),+ endpoint="/v1/chat/completions",+ request={"model": "$MODEL", "messages": [{"role": "user", "content": "cost tracking fixture"}], "max_tokens": 412},+ response=JsonResponse(+ content_type="application/json",+ body={+ "choices": [+ {+ "finish_reason": "stop",+ "index": 0,+ "message": {+ "annotations": [],+ "content": "scripted response",+ "refusal": None,+ "role": "assistant",+ },+ }+ ],+ "created": 1791861646,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ },+ ),+ expected=ExactExpected(+ spend=0.0069512, input_cost=0.004232, output_cost=0.0027192, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_XAI_GROK_4_7_STREAM: Final = CostTrackingTestCase(+ name="bedrock-us.xai.grok-4.7-stream",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.xai.grok-4.7",+ deployment=Deployment(model="bedrock/us.xai.grok-4.7"),+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "stream": True,+ "stream_options": {"include_usage": True},+ },+ response=SseResponse(+ content_type="text/event-stream",+ frames=sse_frames(+ {+ "choices": [+ {"delta": {"content": "", "role": "assistant", "refusal": None}, "finish_reason": None, "index": 0}+ ],+ "created": 1791861761,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopq",+ },+ {+ "choices": [{"delta": {"content": "Hello"}, "finish_reason": None, "index": 0}],+ "created": 1791861761,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJK",+ },+ {+ "choices": [{"delta": {"content": "."}, "finish_reason": None, "index": 0}],+ "created": 1791861761,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",+ },+ {+ "choices": [{"delta": {}, "finish_reason": "stop", "index": 0}],+ "created": 1791861761,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopqrstu",+ },+ {+ "choices": [],+ "created": 1791861761,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ "obfuscation": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01",+ },+ done=True,+ ),+ ),+ expected=ExactExpected(+ spend=0.0069512, input_cost=0.004232, output_cost=0.0027192, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_XAI_GROK_4_7_TOOL_CALL: Final = CostTrackingTestCase(+ name="bedrock-us.xai.grok-4.7-tool_call",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.xai.grok-4.7",+ deployment=Deployment(model="bedrock/us.xai.grok-4.7"),+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "tools": [+ {+ "type": "function",+ "function": {+ "name": "get_weather",+ "description": "Weather forecast for a city",+ "parameters": {+ "type": "object",+ "properties": {+ "city": {"type": "string"},+ "days": {"type": "integer"},+ "units": {"type": "string"},+ },+ "required": ["city"],+ },+ },+ }+ ],+ },+ response=JsonResponse(+ content_type="application/json",+ body={+ "choices": [+ {+ "finish_reason": "tool_calls",+ "index": 0,+ "message": {+ "annotations": [],+ "content": None,+ "refusal": None,+ "role": "assistant",+ "tool_calls": [+ {+ "function": {+ "arguments": '{"city":"Berlin","days":7,"units":"metric"}',+ "name": "get_weather",+ },+ "id": "call_0",+ "type": "function",+ }+ ],+ },+ }+ ],+ "created": 1791861763,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 96,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ },+ ),+ expected=ExactExpected(+ spend=0.0069512, input_cost=0.004232, output_cost=0.0027192, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_XAI_GROK_4_7_REASONING: Final = CostTrackingTestCase(+ name="bedrock-us.xai.grok-4.7-reasoning",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.xai.grok-4.7",+ deployment=Deployment(model="bedrock/us.xai.grok-4.7"),+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "reasoning_effort": "high",+ },+ response=JsonResponse(+ content_type="application/json",+ body={+ "choices": [+ {+ "finish_reason": "stop",+ "index": 0,+ "message": {"annotations": [], "content": "757", "refusal": None, "role": "assistant"},+ }+ ],+ "created": 1791861765,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.xai.grok-4.7",+ "object": "chat.completion",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 300,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ },+ ),+ expected=ExactExpected(+ spend=0.0069512, input_cost=0.004232, output_cost=0.0027192, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_XAI_GROK_4_7_CACHE_READ: Final = with_usage(+ BEDROCK_US_XAI_GROK_4_7_INPUT_TEXT,+ "bedrock-us.xai.grok-4.7-cache_read",+ {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 640},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(+ spend=0.0058312, input_cost=0.003112, output_cost=0.0027192, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT: Final = CostTrackingTestCase(+ name="bedrock-us.openai.gpt-6-sol-input_text",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.openai.gpt-6-sol",+ deployment=Deployment(model="bedrock/us.openai.gpt-6-sol"),+ endpoint="/v1/chat/completions",+ request={"model": "$MODEL", "messages": [{"role": "user", "content": "cost tracking fixture"}], "max_tokens": 412},+ response=JsonResponse(+ content_type="application/json",+ body={+ "choices": [+ {+ "finish_reason": "stop",+ "index": 0,+ "message": {"annotations": [], "content": "Hello.", "refusal": None, "role": "assistant"},+ }+ ],+ "created": 1791861651,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ },+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_OPENAI_GPT_6_SOL_STREAM: Final = CostTrackingTestCase(+ name="bedrock-us.openai.gpt-6-sol-stream",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.openai.gpt-6-sol",+ deployment=Deployment(model="bedrock/us.openai.gpt-6-sol"),+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "stream": True,+ "stream_options": {"include_usage": True},+ },+ response=SseResponse(+ content_type="text/event-stream",+ frames=sse_frames(+ {+ "choices": [+ {"delta": {"content": "", "role": "assistant", "refusal": None}, "finish_reason": None, "index": 0}+ ],+ "created": 1791861768,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopqrstuvwxyzAB",+ },+ {+ "choices": [{"delta": {"content": "Hello"}, "finish_reason": None, "index": 0}],+ "created": 1791861768,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcd",+ },+ {+ "choices": [{"delta": {"content": "."}, "finish_reason": None, "index": 0}],+ "created": 1791861768,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopqr",+ },+ {+ "choices": [{"delta": {}, "finish_reason": "stop", "index": 0}],+ "created": 1791861768,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "system_fingerprint": None,+ "usage": None,+ "obfuscation": "abcdefghijklmnopqrstuvwxyzABCDEFGHI",+ },+ {+ "choices": [],+ "created": 1791861768,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion.chunk",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ "obfuscation": "abcdefghijk",+ },+ done=True,+ ),+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_OPENAI_GPT_6_SOL_REASONING: Final = CostTrackingTestCase(+ name="bedrock-us.openai.gpt-6-sol-reasoning",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="us.openai.gpt-6-sol",+ deployment=Deployment(model="bedrock/us.openai.gpt-6-sol"),+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "reasoning_effort": "high",+ },+ response=JsonResponse(+ content_type="application/json",+ body={+ "choices": [+ {+ "finish_reason": "stop",+ "index": 0,+ "message": {"annotations": [], "content": "757", "refusal": None, "role": "assistant"},+ }+ ],+ "created": 1791861770,+ "id": "chatcmpl-$REQUEST_ID",+ "model": "us.openai.gpt-6-sol",+ "object": "chat.completion",+ "service_tier": "default",+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 300,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": None,+ },+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_OPENAI_GPT_6_SOL_CACHE_READ: Final = with_usage(+ BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT,+ "bedrock-us.openai.gpt-6-sol-cache_read",+ {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 640},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(+ spend=0.0073128, input_cost=0.0027808, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_US_OPENAI_GPT_6_SOL_TIERED_INPUT_ABOVE_272K: Final = with_usage(+ BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT,+ "bedrock-us.openai.gpt-6-sol-tiered_input_above_272k",+ {+ "prompt_tokens": 300000,+ "completion_tokens": 412,+ "total_tokens": 300412,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=1.326798, input_cost=1.32, output_cost=0.006798, prompt_tokens=300000, completion_tokens=412),+)++BEDROCK_US_OPENAI_GPT_6_SOL_TIERED_CACHE_READ_ABOVE_272K: Final = with_usage(+ BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT,+ "bedrock-us.openai.gpt-6-sol-tiered_cache_read_above_272k",+ {+ "prompt_tokens": 300000,+ "completion_tokens": 412,+ "total_tokens": 300412,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 200000},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=0.534798, input_cost=0.528, output_cost=0.006798, prompt_tokens=300000, completion_tokens=412),+)++BEDROCK_US_OPENAI_GPT_6_SOL_TIERED_AT_272K_BOUNDARY: Final = with_usage(+ BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT,+ "bedrock-us.openai.gpt-6-sol-tiered_at_272k_boundary",+ {+ "prompt_tokens": 272000,+ "completion_tokens": 412,+ "total_tokens": 272412,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=0.602932, input_cost=0.5984, output_cost=0.004532, prompt_tokens=272000, completion_tokens=412),+)++CASES: Final[tuple[CostTrackingTestCase, ...]] = (+ BEDROCK_US_XAI_GROK_4_7_INPUT_TEXT,+ BEDROCK_US_XAI_GROK_4_7_STREAM,+ BEDROCK_US_XAI_GROK_4_7_TOOL_CALL,+ BEDROCK_US_XAI_GROK_4_7_REASONING,+ BEDROCK_US_XAI_GROK_4_7_CACHE_READ,+ BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT,+ BEDROCK_US_OPENAI_GPT_6_SOL_STREAM,+ BEDROCK_US_OPENAI_GPT_6_SOL_REASONING,+ BEDROCK_US_OPENAI_GPT_6_SOL_CACHE_READ,+ BEDROCK_US_OPENAI_GPT_6_SOL_TIERED_INPUT_ABOVE_272K,+ BEDROCK_US_OPENAI_GPT_6_SOL_TIERED_CACHE_READ_ABOVE_272K,+ BEDROCK_US_OPENAI_GPT_6_SOL_TIERED_AT_272K_BOUNDARY,+)++PARITY: Final[tuple[StreamParityTestCase, ...]] = (+ StreamParityTestCase(plain=BEDROCK_US_XAI_GROK_4_7_INPUT_TEXT, streamed=BEDROCK_US_XAI_GROK_4_7_STREAM),+ StreamParityTestCase(plain=BEDROCK_US_OPENAI_GPT_6_SOL_INPUT_TEXT, streamed=BEDROCK_US_OPENAI_GPT_6_SOL_STREAM),+)diff --git a/tests/integration/cost_calculation/cases/bedrock_mantle.py b/tests/integration/cost_calculation/cases/bedrock_mantle.pynew file mode 100644index 00000000000..714c6f2811f--- /dev/null+++ b/tests/integration/cost_calculation/cases/bedrock_mantle.py@@ -0,0 +1,521 @@+"""Bedrock Mantle cost tracking cases for openai.gpt-6-sol, a mode responses row that LiteLLM serves on /openai/v1/responses for both /v1/responses and chat clients."""++from __future__ import annotations++from typing import Final++from integration.cost_calculation.cases.openai import with_usage+from integration.cost_calculation.cost_tracking_case import (+ CostTrackingTestCase,+ Deployment,+ ExactExpected,+ JsonResponse,+ SseResponse,+)+from integration.cost_calculation.stream_parity.case import StreamParityTestCase, sse_frames+++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON: Final = CostTrackingTestCase(+ name="bedrock_mantle-openai.gpt-6-sol-responses_json",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="bedrock_mantle/openai.gpt-6-sol",+ endpoint="/v1/responses",+ request={"model": "$MODEL", "input": "cost tracking fixture", "max_output_tokens": 412, "stream": False},+ response=JsonResponse(+ content_type="application/json",+ body={+ "background": False,+ "billing": {"payer": "developer"},+ "completed_at": 1791861771,+ "created_at": 1791861771,+ "error": None,+ "frequency_penalty": 0.0,+ "id": "resp_$REQUEST_ID",+ "incomplete_details": None,+ "instructions": None,+ "max_output_tokens": 64,+ "max_tool_calls": None,+ "metadata": {},+ "model": "openai.gpt-6-sol",+ "object": "response",+ "output": [+ {+ "content": [{"annotations": [], "logprobs": [], "text": "Hello!", "type": "output_text"}],+ "id": "msg_$REQUEST_ID",+ "phase": "final_answer",+ "role": "assistant",+ "status": "completed",+ "type": "message",+ }+ ],+ "parallel_tool_calls": True,+ "presence_penalty": 0.0,+ "previous_response_id": None,+ "prompt_cache_key": None,+ "prompt_cache_retention": "in_memory",+ "reasoning": {"summary": None, "effort": "medium", "context": "all_turns"},+ "safety_identifier": None,+ "service_tier": "default",+ "status": "completed",+ "store": True,+ "temperature": 1.0,+ "text": {"format": {"type": "text"}, "verbosity": "medium"},+ "tool_choice": "auto",+ "tools": [],+ "top_logprobs": 0,+ "top_p": 0.98,+ "truncation": "disabled",+ "usage": {+ "input_tokens": 1840,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 0},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 2252,+ },+ "user": None,+ "moderation": None,+ },+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_STREAM: Final = CostTrackingTestCase(+ name="bedrock_mantle-openai.gpt-6-sol-responses_stream",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="bedrock_mantle/openai.gpt-6-sol",+ endpoint="/v1/responses",+ request={"model": "$MODEL", "input": "cost tracking fixture", "max_output_tokens": 412, "stream": True},+ response=SseResponse(+ content_type="text/event-stream",+ frames=sse_frames(+ {+ "response": {+ "background": False,+ "completed_at": None,+ "created_at": 1791861771,+ "error": None,+ "frequency_penalty": 0.0,+ "id": "resp_$REQUEST_ID",+ "incomplete_details": None,+ "instructions": None,+ "max_output_tokens": 64,+ "max_tool_calls": None,+ "metadata": {},+ "model": "openai.gpt-6-sol",+ "object": "response",+ "output": [],+ "parallel_tool_calls": True,+ "presence_penalty": 0.0,+ "previous_response_id": None,+ "prompt_cache_key": None,+ "prompt_cache_retention": "in_memory",+ "reasoning": {"summary": None, "effort": "medium", "context": "all_turns"},+ "safety_identifier": None,+ "service_tier": "auto",+ "status": "in_progress",+ "store": True,+ "temperature": 1.0,+ "text": {"format": {"type": "text"}, "verbosity": "medium"},+ "tool_choice": "auto",+ "tools": [],+ "top_logprobs": 0,+ "top_p": 0.98,+ "truncation": "disabled",+ "usage": None,+ "user": None,+ "moderation": None,+ },+ "sequence_number": 0,+ "type": "response.created",+ },+ {+ "response": {+ "background": False,+ "completed_at": None,+ "created_at": 1791861771,+ "error": None,+ "frequency_penalty": 0.0,+ "id": "resp_$REQUEST_ID",+ "incomplete_details": None,+ "instructions": None,+ "max_output_tokens": 64,+ "max_tool_calls": None,+ "metadata": {},+ "model": "openai.gpt-6-sol",+ "object": "response",+ "output": [],+ "parallel_tool_calls": True,+ "presence_penalty": 0.0,+ "previous_response_id": None,+ "prompt_cache_key": None,+ "prompt_cache_retention": "in_memory",+ "reasoning": {"summary": None, "effort": "medium", "context": "all_turns"},+ "safety_identifier": None,+ "service_tier": "auto",+ "status": "in_progress",+ "store": True,+ "temperature": 1.0,+ "text": {"format": {"type": "text"}, "verbosity": "medium"},+ "tool_choice": "auto",+ "tools": [],+ "top_logprobs": 0,+ "top_p": 0.98,+ "truncation": "disabled",+ "usage": None,+ "user": None,+ "moderation": None,+ },+ "sequence_number": 1,+ "type": "response.in_progress",+ },+ {+ "item": {+ "content": [],+ "id": "msg_$REQUEST_ID",+ "phase": "final_answer",+ "role": "assistant",+ "status": "in_progress",+ "type": "message",+ },+ "output_index": 0,+ "sequence_number": 2,+ "type": "response.output_item.added",+ },+ {+ "content_index": 0,+ "item_id": "msg_$REQUEST_ID",+ "output_index": 0,+ "part": {"annotations": [], "logprobs": [], "text": "", "type": "output_text"},+ "sequence_number": 3,+ "type": "response.content_part.added",+ },+ {+ "content_index": 0,+ "delta": "Hello",+ "item_id": "msg_$REQUEST_ID",+ "logprobs": [],+ "obfuscation": "abcdefghijklmnopqr",+ "output_index": 0,+ "sequence_number": 4,+ "type": "response.output_text.delta",+ },+ {+ "content_index": 0,+ "delta": "!",+ "item_id": "msg_$REQUEST_ID",+ "logprobs": [],+ "obfuscation": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",+ "output_index": 0,+ "sequence_number": 5,+ "type": "response.output_text.delta",+ },+ {+ "content_index": 0,+ "item_id": "msg_$REQUEST_ID",+ "logprobs": [],+ "output_index": 0,+ "sequence_number": 6,+ "text": "Hello!",+ "type": "response.output_text.done",+ },+ {+ "content_index": 0,+ "item_id": "msg_$REQUEST_ID",+ "output_index": 0,+ "part": {"annotations": [], "logprobs": [], "text": "Hello!", "type": "output_text"},+ "sequence_number": 7,+ "type": "response.content_part.done",+ },+ {+ "item": {+ "content": [{"annotations": [], "logprobs": [], "text": "Hello!", "type": "output_text"}],+ "id": "msg_$REQUEST_ID",+ "phase": "final_answer",+ "role": "assistant",+ "status": "completed",+ "type": "message",+ },+ "output_index": 0,+ "sequence_number": 8,+ "type": "response.output_item.done",+ },+ {+ "response": {+ "background": False,+ "completed_at": 1791861772,+ "created_at": 1791861771,+ "error": None,+ "frequency_penalty": 0.0,+ "id": "resp_$REQUEST_ID",+ "incomplete_details": None,+ "instructions": None,+ "max_output_tokens": 64,+ "max_tool_calls": None,+ "metadata": {},+ "model": "openai.gpt-6-sol",+ "object": "response",+ "output": [+ {+ "content": [{"annotations": [], "logprobs": [], "text": "Hello!", "type": "output_text"}],+ "id": "msg_$REQUEST_ID",+ "phase": "final_answer",+ "role": "assistant",+ "status": "completed",+ "type": "message",+ }+ ],+ "parallel_tool_calls": True,+ "presence_penalty": 0.0,+ "previous_response_id": None,+ "prompt_cache_key": None,+ "prompt_cache_retention": "in_memory",+ "reasoning": {"summary": None, "effort": "medium", "context": "all_turns"},+ "safety_identifier": None,+ "service_tier": "default",+ "status": "completed",+ "store": True,+ "temperature": 1.0,+ "text": {"format": {"type": "text"}, "verbosity": "medium"},+ "tool_choice": "auto",+ "tools": [],+ "top_logprobs": 0,+ "top_p": 0.98,+ "truncation": "disabled",+ "usage": {+ "input_tokens": 1840,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 0},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 2252,+ },+ "user": None,+ "moderation": None,+ },+ "sequence_number": 9,+ "type": "response.completed",+ },+ done=False,+ ),+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_REASONING: Final = CostTrackingTestCase(+ name="bedrock_mantle-openai.gpt-6-sol-responses_reasoning",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="bedrock_mantle/openai.gpt-6-sol",+ endpoint="/v1/responses",+ request={+ "model": "$MODEL",+ "input": "cost tracking fixture",+ "max_output_tokens": 412,+ "stream": False,+ "reasoning": {"effort": "high"},+ },+ response=JsonResponse(+ content_type="application/json",+ body={+ "background": False,+ "billing": {"payer": "developer"},+ "completed_at": 1791861773,+ "created_at": 1791861772,+ "error": None,+ "frequency_penalty": 0.0,+ "id": "resp_$REQUEST_ID",+ "incomplete_details": None,+ "instructions": None,+ "max_output_tokens": 2048,+ "max_tool_calls": None,+ "metadata": {},+ "model": "openai.gpt-6-sol",+ "object": "response",+ "output": [+ {+ "content": [],+ "encrypted_content": "rsn_rru6BQHgUc/VWS5vRIAlHwIFeG7RzPj6s6ycKY/RZlUM5dqF0VNyuAaJUtQ/+O5IKuX/AF8AAQAVYXdzLWNyeXB0by1wdWJsaWMta2V5AERBaFdiZnh2QVRaZFNMS0ZCcTJVNFU1WEs0ZHpxQWpmQjJWQ3lrSW05TU15NWtpdERENHdVWC9uMlk1Ukk4OWpLUGc9PQABABFhd3Mta21zLWhpZXJhcmNoeQAKYmVybS1zdG9yZQBcXPp4b5qq1rMOAJCEMPOm1n1nzGavCPmKLYo+FgTyexPQO0PepR8jRQ3zVYSaLucS0FaGd1vcWrKrWKX8eIKD7wfHZpbMRbHMetv9w7xqCa4AE7hEPeWZthEccJMCAAAQACD+kEmiADTYVTf4H4U4QPblaMH/uE6BZviKmxyR4w3Xmwt5lcAEk0qVMG8al0lAk/////8AAAABAAAAAAAAAAAAAAABAAAA79DoUN9BMZV9CqY2mV0QW7ClRkkz38xKlz6LsDiZhV7/t7HA5FtCgxQNoW7vsVlddML725aymJQaphYk5S6FlvHrCiTlXBN+rVIy4HladKMznUZ/ObJd5wd/PdnQPur169UkSOlMa7UrZ7LP3spUG+mX7VS/yIoBKEDj7gK0MEblJ/AOJUtMKKcPh+AbuTXhLEMLl5bbsIozmRPj+w/kN3btLUIeWXijbzeoaO4//v8ia9wXUS4QUTduf9IJm7RgGy2qfyKQf4Ieiw2ZXEsFL5uuCR5P2IkFZ+gSktZtEV4S5rrvmpVmCuUdpmlYsQ/bLAO/7LgpKYHfx/v//f0seABnMGUCMCra6yiTJwzvp7p/t98exwMQnyJV8XMw6kCkn1LxNZbdBAL8z22Cu6BTkbAqgFS/DAIxAPwlq5ScUMLeMMuY5gotOj8u5jmQGG6RL7JxaUQCu/cNsZIa0oDUK5GlZkHGhkI54w==",+ "id": "rs_$REQUEST_ID",+ "summary": [],+ "type": "reasoning",+ },+ {+ "content": [{"annotations": [], "logprobs": [], "text": "757", "type": "output_text"}],+ "id": "msg_$REQUEST_ID",+ "phase": "final_answer",+ "role": "assistant",+ "status": "completed",+ "type": "message",+ },+ ],+ "parallel_tool_calls": True,+ "presence_penalty": 0.0,+ "previous_response_id": None,+ "prompt_cache_key": None,+ "prompt_cache_retention": "in_memory",+ "reasoning": {"summary": None, "effort": "medium", "context": "all_turns"},+ "safety_identifier": None,+ "service_tier": "default",+ "status": "completed",+ "store": True,+ "temperature": 1.0,+ "text": {"format": {"type": "text"}, "verbosity": "medium"},+ "tool_choice": "auto",+ "tools": [],+ "top_logprobs": 0,+ "top_p": 0.98,+ "truncation": "disabled",+ "usage": {+ "input_tokens": 1840,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 0},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 300},+ "total_tokens": 2252,+ },+ "user": None,+ "moderation": None,+ },+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_CHAT_JSON: Final = CostTrackingTestCase(+ name="bedrock_mantle-openai.gpt-6-sol-chat_json",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="bedrock_mantle/openai.gpt-6-sol",+ endpoint="/v1/chat/completions",+ request={"model": "$MODEL", "messages": [{"role": "user", "content": "cost tracking fixture"}], "max_tokens": 412},+ response=JsonResponse(+ content_type="application/json",+ body={+ "background": False,+ "billing": {"payer": "developer"},+ "completed_at": 1791861772,+ "created_at": 1791861772,+ "error": None,+ "frequency_penalty": 0.0,+ "id": "resp_$REQUEST_ID",+ "incomplete_details": None,+ "instructions": "You are a deterministic pricing-harness assistant. Keep answers to a single short line.",+ "max_output_tokens": 64,+ "max_tool_calls": None,+ "metadata": {},+ "model": "openai.gpt-6-sol",+ "object": "response",+ "output": [+ {+ "content": [{"annotations": [], "logprobs": [], "text": "Hello.", "type": "output_text"}],+ "id": "msg_$REQUEST_ID",+ "phase": "final_answer",+ "role": "assistant",+ "status": "completed",+ "type": "message",+ }+ ],+ "parallel_tool_calls": True,+ "presence_penalty": 0.0,+ "previous_response_id": None,+ "prompt_cache_key": None,+ "prompt_cache_retention": "in_memory",+ "reasoning": {"summary": None, "effort": "medium", "context": "all_turns"},+ "safety_identifier": None,+ "service_tier": "default",+ "status": "completed",+ "store": True,+ "temperature": 1.0,+ "text": {"format": {"type": "text"}, "verbosity": "medium"},+ "tool_choice": "auto",+ "tools": [],+ "top_logprobs": 0,+ "top_p": 0.98,+ "truncation": "disabled",+ "usage": {+ "input_tokens": 1840,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 0},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 2252,+ },+ "user": None,+ "moderation": None,+ },+ ),+ expected=ExactExpected(+ spend=0.00858, input_cost=0.004048, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_CACHE_READ: Final = with_usage(+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON,+ "bedrock_mantle-openai.gpt-6-sol-responses_cache_read",+ {+ "input_tokens": 1840,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 640},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 2252,+ },+ ExactExpected(+ spend=0.0073128, input_cost=0.0027808, output_cost=0.004532, prompt_tokens=1840, completion_tokens=412+ ),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_TIERED_INPUT_ABOVE_272K: Final = with_usage(+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON,+ "bedrock_mantle-openai.gpt-6-sol-tiered_input_above_272k",+ {+ "input_tokens": 300000,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 0},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 300412,+ },+ ExactExpected(spend=1.326798, input_cost=1.32, output_cost=0.006798, prompt_tokens=300000, completion_tokens=412),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_TIERED_CACHE_READ_ABOVE_272K: Final = with_usage(+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON,+ "bedrock_mantle-openai.gpt-6-sol-tiered_cache_read_above_272k",+ {+ "input_tokens": 300000,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 200000},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 300412,+ },+ ExactExpected(spend=0.534798, input_cost=0.528, output_cost=0.006798, prompt_tokens=300000, completion_tokens=412),+)++BEDROCK_MANTLE_OPENAI_GPT_6_SOL_TIERED_AT_272K_BOUNDARY: Final = with_usage(+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON,+ "bedrock_mantle-openai.gpt-6-sol-tiered_at_272k_boundary",+ {+ "input_tokens": 272000,+ "input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 0},+ "output_tokens": 412,+ "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 272412,+ },+ ExactExpected(spend=0.602932, input_cost=0.5984, output_cost=0.004532, prompt_tokens=272000, completion_tokens=412),+)++CASES: Final[tuple[CostTrackingTestCase, ...]] = (+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_STREAM,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_REASONING,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_CHAT_JSON,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_CACHE_READ,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_TIERED_INPUT_ABOVE_272K,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_TIERED_CACHE_READ_ABOVE_272K,+ BEDROCK_MANTLE_OPENAI_GPT_6_SOL_TIERED_AT_272K_BOUNDARY,+)++PARITY: Final[tuple[StreamParityTestCase, ...]] = (+ StreamParityTestCase(+ plain=BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_JSON, streamed=BEDROCK_MANTLE_OPENAI_GPT_6_SOL_RESPONSES_STREAM+ ),+)diff --git a/tests/integration/cost_calculation/cases/xai.py b/tests/integration/cost_calculation/cases/xai.pynew file mode 100644index 00000000000..2ee676fd4d0--- /dev/null+++ b/tests/integration/cost_calculation/cases/xai.py@@ -0,0 +1,303 @@+"""xai cost tracking cases for grok-4.7 (OpenAI-compatible chat JSON and SSE, inclusive 200k tier)."""++from __future__ import annotations++from typing import Final++from integration.cost_calculation.cases.openai import with_usage+from integration.cost_calculation.cost_tracking_case import (+ CostTrackingTestCase,+ Deployment,+ ExactExpected,+ JsonResponse,+ SseResponse,+)+from integration.cost_calculation.stream_parity.case import StreamParityTestCase, sse_frames+from integration.cost_calculation.cases.misc import XAI_GROK_4_7_INPUT_TEXT++XAI_GROK_4_7_STREAM: Final = CostTrackingTestCase(+ name="xai-grok-4.7-stream",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="xai/grok-4.7",+ known_bug="streamed xai responses bill the right total but the spend row splits it as input_cost 0 and output_cost = total: _stamp_streaming_usage_cost writes the stream total onto usage.cost and litellm/llms/xai/cost_calculator.py::cost_per_token reads usage.cost as an xAI reported price",+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "stream": True,+ "stream_options": {"include_usage": True},+ },+ response=SseResponse(+ content_type="text/event-stream",+ frames=sse_frames(+ {+ "id": "$REQUEST_ID",+ "object": "chat.completion.chunk",+ "created": 1791861751,+ "model": "grok-4.7",+ "choices": [{"index": 0, "delta": {"content": "Hello", "role": "assistant"}}],+ "system_fingerprint": "fp_c60958d81f66f847",+ "service_tier": "default",+ },+ {+ "id": "$REQUEST_ID",+ "object": "chat.completion.chunk",+ "created": 1791861751,+ "model": "grok-4.7",+ "choices": [{"index": 0, "delta": {"content": "."}}],+ "system_fingerprint": "fp_c60958d81f66f847",+ "service_tier": "default",+ },+ {+ "id": "$REQUEST_ID",+ "object": "chat.completion.chunk",+ "created": 1791861751,+ "model": "grok-4.7",+ "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}],+ "system_fingerprint": "fp_c60958d81f66f847",+ "service_tier": "default",+ },+ {+ "id": "$REQUEST_ID",+ "object": "chat.completion.chunk",+ "created": 1791861751,+ "model": "grok-4.7",+ "choices": [],+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": "fp_c60958d81f66f847",+ "service_tier": "default",+ },+ done=True,+ ),+ ),+ expected=ExactExpected(+ spend=0.006152, input_cost=0.00368, output_cost=0.002472, prompt_tokens=1840, completion_tokens=412+ ),+)++XAI_GROK_4_7_TOOL_CALL: Final = CostTrackingTestCase(+ name="xai-grok-4.7-tool_call",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="xai/grok-4.7",+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "tools": [+ {+ "type": "function",+ "function": {+ "name": "get_weather",+ "description": "Weather forecast for a city",+ "parameters": {+ "type": "object",+ "properties": {+ "city": {"type": "string"},+ "days": {"type": "integer"},+ "units": {"type": "string"},+ },+ "required": ["city"],+ },+ },+ }+ ],+ "tool_choice": "auto",+ },+ response=JsonResponse(+ content_type="application/json",+ body={+ "id": "$REQUEST_ID",+ "object": "chat.completion",+ "created": 1791861753,+ "model": "grok-4.7",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "",+ "reasoning_content": "Fetching a 7-day weather forecast for Berlin in metric units.",+ "tool_calls": [+ {+ "id": "call-f9881b6d-f559-48ba-afed-83e5a96c7d52-0",+ "function": {+ "name": "get_weather",+ "arguments": '{"city":"Berlin","days":7,"units":"metric"}',+ },+ "type": "function",+ }+ ],+ "refusal": None,+ },+ "finish_reason": "tool_calls",+ }+ ],+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 96,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": "fp_c60958d81f66f847",+ "service_tier": "default",+ },+ ),+ expected=ExactExpected(+ spend=0.006152, input_cost=0.00368, output_cost=0.002472, prompt_tokens=1840, completion_tokens=412+ ),+)++XAI_GROK_4_7_REASONING: Final = CostTrackingTestCase(+ name="xai-grok-4.7-reasoning",+ covers="quota_management.spend_tracking.cost_matrix.logs_cost",+ model="xai/grok-4.7",+ endpoint="/v1/chat/completions",+ request={+ "model": "$MODEL",+ "messages": [{"role": "user", "content": "cost tracking fixture"}],+ "max_tokens": 412,+ "reasoning_effort": "high",+ },+ response=JsonResponse(+ content_type="application/json",+ body={+ "id": "$REQUEST_ID",+ "object": "chat.completion",+ "created": 1791861757,+ "model": "grok-4.7",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "757",+ "reasoning_content": "I need to calculate 17 times 23 and add the number of days "+ "in a leap year.",+ "refusal": None,+ },+ "finish_reason": "stop",+ }+ ],+ "usage": {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 300,+ "rejected_prediction_tokens": 0,+ },+ },+ "system_fingerprint": "fp_c60958d81f66f847",+ "service_tier": "default",+ },+ ),+ expected=ExactExpected(+ spend=0.006152, input_cost=0.00368, output_cost=0.002472, prompt_tokens=1840, completion_tokens=412+ ),+)++XAI_GROK_4_7_CACHE_READ: Final = with_usage(+ XAI_GROK_4_7_INPUT_TEXT,+ "xai-grok-4.7-cache_read",+ {+ "prompt_tokens": 1840,+ "completion_tokens": 412,+ "total_tokens": 2252,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 640},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=0.005192, input_cost=0.00272, output_cost=0.002472, prompt_tokens=1840, completion_tokens=412),+)++XAI_GROK_4_7_TIERED_INPUT_ABOVE_200K: Final = with_usage(+ XAI_GROK_4_7_INPUT_TEXT,+ "xai-grok-4.7-tiered_input_above_200k",+ {+ "prompt_tokens": 300000,+ "completion_tokens": 412,+ "total_tokens": 300412,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=1.204944, input_cost=1.2, output_cost=0.004944, prompt_tokens=300000, completion_tokens=412),+)++XAI_GROK_4_7_TIERED_CACHE_READ_ABOVE_200K: Final = with_usage(+ XAI_GROK_4_7_INPUT_TEXT,+ "xai-grok-4.7-tiered_cache_read_above_200k",+ {+ "prompt_tokens": 300000,+ "completion_tokens": 412,+ "total_tokens": 300412,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 200000},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=0.604944, input_cost=0.6, output_cost=0.004944, prompt_tokens=300000, completion_tokens=412),+)++XAI_GROK_4_7_TIERED_AT_200K_BOUNDARY: Final = with_usage(+ XAI_GROK_4_7_INPUT_TEXT,+ "xai-grok-4.7-tiered_at_200k_boundary",+ {+ "prompt_tokens": 200000,+ "completion_tokens": 412,+ "total_tokens": 200412,+ "prompt_tokens_details": {"audio_tokens": 0, "cache_write_tokens": 0, "cached_tokens": 0},+ "completion_tokens_details": {+ "accepted_prediction_tokens": 0,+ "audio_tokens": 0,+ "reasoning_tokens": 0,+ "rejected_prediction_tokens": 0,+ },+ },+ ExactExpected(spend=0.804944, input_cost=0.8, output_cost=0.004944, prompt_tokens=200000, completion_tokens=412),+)++CASES: Final[tuple[CostTrackingTestCase, ...]] = (+ XAI_GROK_4_7_STREAM,+ XAI_GROK_4_7_TOOL_CALL,+ XAI_GROK_4_7_REASONING,+ XAI_GROK_4_7_CACHE_READ,+ XAI_GROK_4_7_TIERED_INPUT_ABOVE_200K,+ XAI_GROK_4_7_TIERED_CACHE_READ_ABOVE_200K,+ XAI_GROK_4_7_TIERED_AT_200K_BOUNDARY,+)++PARITY: Final[tuple[StreamParityTestCase, ...]] = ()diff --git a/tests/integration/cost_calculation/catalog.py b/tests/integration/cost_calculation/catalog.pyindex 9702c2f9d20..15dec65c260 100644--- a/tests/integration/cost_calculation/catalog.py+++ b/tests/integration/cost_calculation/catalog.py@@ -9,7 +9,9 @@ from integration.cost_calculation.cases import (anthropic,azure,batch_realtime,+ bedrock_chat_completions,bedrock_converse,+ bedrock_mantle,decisions,fireworks_ai,gemini,@@ -17,6 +19,7 @@ from integration.cost_calculation.cases import (openai,together_ai,vertex_ai,+ xai,)from integration.cost_calculation.cost_tracking_case import (COST_MAP,@@ -38,12 +41,15 @@ _PROVIDER_MODULES: Final = (anthropic,gemini,bedrock_converse,+ bedrock_chat_completions,+ bedrock_mantle,decisions,vertex_ai,azure,fireworks_ai,together_ai,misc,+ xai,)CASES: Final[tuple[CostTrackingTestCase, ...]] = tuple(case for module in _PROVIDER_MODULES for case in module.CASES)PARITY_CASES: Final[tuple[StreamParityTestCase, ...]] = tuple(diff --git a/tests/integration/cost_calculation/cost_map.py b/tests/integration/cost_calculation/cost_map.pyindex 85388dc05b5..eb56831758d 100644--- a/tests/integration/cost_calculation/cost_map.py+++ b/tests/integration/cost_calculation/cost_map.py@@ -795,11 +795,70 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = {"input_cost_per_token": 2e-06,"output_cost_per_token": 6e-06,"cache_read_input_token_cost": 5e-07,+ "input_cost_per_token_above_200k_tokens": 4e-06,+ "output_cost_per_token_above_200k_tokens": 1.2e-05,+ "cache_read_input_token_cost_above_200k_tokens": 1e-06,+ "supports_reasoning": True,+ "supports_prompt_caching": True,"max_tokens": 500000,"max_input_tokens": 500000,"max_output_tokens": 500000,"supports_function_calling": True,},+ "us.xai.grok-4.7": {+ "litellm_provider": "bedrock_converse",+ "mode": "chat",+ "input_cost_per_token": 2.3e-06,+ "output_cost_per_token": 6.6e-06,+ "cache_read_input_token_cost": 5.5e-07,+ "max_tokens": 500000,+ "max_input_tokens": 500000,+ "max_output_tokens": 500000,+ "supports_function_calling": True,+ "supports_reasoning": True,+ "supports_bedrock_runtime_chat_completions_tools_with_reasoning": True,+ "supports_bedrock_runtime_chat_completions_response_format": True,+ "supported_endpoints": ["/v1/chat/completions"],+ },+ "us.openai.gpt-6-sol": {+ "litellm_provider": "bedrock_converse",+ "mode": "chat",+ "input_cost_per_token": 2.2e-06,+ "output_cost_per_token": 1.1e-05,+ "cache_read_input_token_cost": 2.2e-07,+ "cache_creation_input_token_cost": 2.75e-06,+ "input_cost_per_token_above_272k_tokens": 4.4e-06,+ "output_cost_per_token_above_272k_tokens": 1.65e-05,+ "cache_read_input_token_cost_above_272k_tokens": 4.4e-07,+ "cache_creation_input_token_cost_above_272k_tokens": 5.5e-06,+ "max_tokens": 128000,+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "supports_function_calling": True,+ "supports_reasoning": True,+ "supports_prompt_caching": True,+ "supports_bedrock_runtime_chat_completions_response_format": True,+ "supported_endpoints": ["/v1/chat/completions", "/v1/responses"],+ },+ "bedrock_mantle/openai.gpt-6-sol": {+ "litellm_provider": "bedrock_mantle",+ "mode": "responses",+ "input_cost_per_token": 2.2e-06,+ "output_cost_per_token": 1.1e-05,+ "cache_read_input_token_cost": 2.2e-07,+ "cache_creation_input_token_cost": 2.75e-06,+ "input_cost_per_token_above_272k_tokens": 4.4e-06,+ "output_cost_per_token_above_272k_tokens": 1.65e-05,+ "cache_read_input_token_cost_above_272k_tokens": 4.4e-07,+ "cache_creation_input_token_cost_above_272k_tokens": 5.5e-06,+ "max_tokens": 128000,+ "max_input_tokens": 400000,+ "max_output_tokens": 128000,+ "supports_function_calling": True,+ "supports_reasoning": True,+ "supports_prompt_caching": True,+ "supported_endpoints": ["/v1/chat/completions", "/v1/responses"],+ },"us.anthropic.claude-opus-5-5": {"cache_creation_input_token_cost_above_1hr": 8.8e-06,"litellm_provider": "bedrock_converse",diff --git a/tests/integration/cost_calculation/cost_tracking_case.py b/tests/integration/cost_calculation/cost_tracking_case.pyindex 52319a79beb..c71174948ac 100644--- a/tests/integration/cost_calculation/cost_tracking_case.py+++ b/tests/integration/cost_calculation/cost_tracking_case.py@@ -44,6 +44,11 @@ class CostMapEntry(BaseModel):max_output_tokens: int | None = Nonesupports_function_calling: bool | None = Nonesupports_none_reasoning_effort: bool | None = None+ supports_reasoning: bool | None = None+ supports_prompt_caching: bool | None = None+ supported_endpoints: tuple[str, ...] | None = None+ supports_bedrock_runtime_chat_completions_tools_with_reasoning: bool | None = None+ supports_bedrock_runtime_chat_completions_response_format: bool | None = Nonecache_creation_input_token_cost_above_100k_tokens: float | None = Nonecache_creation_input_token_cost_above_1hr_above_100k_tokens: float | None = Nonecache_read_input_token_cost_above_100k_tokens: float | None = None@@ -260,6 +265,7 @@ class CostTrackingTestCase(BaseModel):name: strcovers: str+ known_bug: str | None = Nonemodel: strendpoint: (Literal[@@ -520,6 +526,7 @@ _PROVIDER_PREFIXES: Final[Mapping[str, str]] = MappingProxyType("anthropic": "anthropic","bedrock": "bedrock","bedrock_converse": "bedrock/converse",+ "bedrock_mantle": "bedrock_mantle","deepgram": "deepgram","text-completion-openai": "text-completion-openai","cohere": "cohere",@@ -561,6 +568,13 @@ _LITELLM_PARAMS: Final[Mapping[str, Mapping[str, str]]] = MappingProxyType("aws_region_name": "us-east-1",}),+ "bedrock_mantle": MappingProxyType(+ {+ "aws_access_key_id": "AKIASCRIPTEDPROVIDER",+ "aws_secret_access_key": "scripted-secret",+ "aws_region_name": "us-east-1",+ }+ ),"deepgram": MappingProxyType({}),"text-completion-openai": MappingProxyType({}),"cohere": MappingProxyType({}),diff --git a/tests/integration/cost_calculation/test_cost_tracking.py b/tests/integration/cost_calculation/test_cost_tracking.pyindex 9db55589fb3..ce30cc7f643 100644--- a/tests/integration/cost_calculation/test_cost_tracking.py+++ b/tests/integration/cost_calculation/test_cost_tracking.py@@ -42,9 +42,14 @@ if _data_errors := data_errors():raise ValueError("\n".join(_data_errors))-_CASES: Final = tuple(- pytest.param(case, marks=pytest.mark.covers(case.covers), id=case.name) for case in STANDALONE_CASES-)+def _marks(case: CostTrackingTestCase) -> tuple[pytest.MarkDecorator, ...]:+ bug: Final = (+ (pytest.mark.xfail(strict=True, reason=f"BUG: {case.known_bug}"),) if case.known_bug is not None else ()+ )+ return (pytest.mark.covers(case.covers), *bug)+++_CASES: Final = tuple(pytest.param(case, marks=_marks(case), id=case.name) for case in STANDALONE_CASES)def _wav_bytes(seconds: float) -> bytes: