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]

chore: merge main into litellm_cost_shard_audio_images

kerry0afb9bb58755
diff --cc tests/integration/contracts.json
index ac9552484fc,d04e7f97bf7..dc6b218feb4
--- a/tests/integration/contracts.json
+++ b/tests/integration/contracts.json
@@@ -1336,53 -1336,71 +1336,119 @@@
"tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[us.anthropic.claude-opus-5-v1:0-stream_full_usage]": [
"quota_management.spend_tracking.scripted_wire.logs_cost"
],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[whisper-next-transcriptions-per-second]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[whisper-verbose-next-transcriptions-duration]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[gpt-4o-transcribe-next-transcriptions-tokens]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[nova-next-transcriptions-per-second]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[azure-whisper-next-transcriptions-deployment]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[tts-next-speech-per-character]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[tts-next-hd-speech-per-character]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[azure-tts-next-speech-deployment]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[dall-e-3-next-images-standard]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[dall-e-3-next-images-hd]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[dall-e-3-next-images-wide]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[dall-e-3-next-images-two]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[gpt-image-next-images-low]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[imagen-next-images-one]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[amazon-nova-canvas-next-images-one]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[gpt-image-next-images-edit]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
++ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[azure-text-embeddings-4-large-deployment]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[bedrock-cohere-embeddings-v4]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[bedrock-cohere-rerank-v4]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[bedrock-embeddings-titan-v2]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[cohere-embeddings-v5]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[cohere-rerank-v4-one]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[cohere-rerank-v4-three]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[cohere-rerank-v4-total-tokens-fallback]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[fireworks-embeddings-v1]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[gemini-embeddings-002]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[omni-moderations-next-list]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[omni-moderations-next-single]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-completions-openai-basic]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-completions-openai-n-best]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-completions-openai-stream-usage]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-embeddings-3-large-dimensions]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-embeddings-4-small-batch]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-embeddings-4-small-single]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[text-embeddings-4-small-token-array]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[together-completions-v1]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[together-embeddings-v1]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
+ ],
+ "tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[vertex-embeddings-text-006]": [
+ "quota_management.spend_tracking.cost_matrix.logs_cost"
],
"tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[gpt-5.6-responses_cache_read]": [
"quota_management.spend_tracking.cost_matrix.logs_cost"
diff --cc tests/integration/cost_calculation/cost_tracking_case.py
index 1869a394016,e24f5d76d0d..617b68bdce0
--- a/tests/integration/cost_calculation/cost_tracking_case.py
+++ b/tests/integration/cost_calculation/cost_tracking_case.py
@@@ -209,10 -176,7 +212,11 @@@ class CostTrackingTestCase(BaseModel)
prefix: Final = (
"openai"
if provider == "openai"
- and (self.endpoint == "/v1/responses" or self.rates.mode in {"chat", "embedding", "moderation"})
+ and (
+ self.endpoint == "/v1/responses"
- or self.rates.mode in {"chat", "audio_transcription", "audio_speech", "image_generation"}
++ or self.rates.mode
++ in {"chat", "embedding", "moderation", "audio_transcription", "audio_speech", "image_generation"}
+ )
else "openai/responses"
if provider == "openai"
else _PROVIDER_PREFIXES.get(provider)
@@@ -246,11 -210,12 +250,14 @@@ class _CasesFile(BaseModel)
_PROVIDER_PREFIXES: Final[Mapping[str, str]] = MappingProxyType(
{
"anthropic": "anthropic",
+ "bedrock": "bedrock",
"bedrock_converse": "bedrock/converse",
+ "deepgram": "deepgram",
+ "text-completion-openai": "text-completion-openai",
+ "cohere": "cohere",
- "bedrock": "bedrock",
"vertex_ai-language-models": "vertex_ai",
+ "vertex_ai-image-models": "vertex_ai",
+ "vertex_ai-embedding-models": "vertex_ai",
"gemini": "",
"together_ai": "",
"fireworks_ai": "",
@@@ -274,13 -241,12 +281,18 @@@ _LITELLM_PARAMS: Final[Mapping[str, Map
"aws_region_name": "us-east-1",
}
),
+ "deepgram": MappingProxyType({}),
++ "text-completion-openai": MappingProxyType({}),
++ "cohere": MappingProxyType({}),
"vertex_ai-language-models": MappingProxyType(
{"vertex_project": "cc-scripted-project", "vertex_location": "us-central1"}
),
+ "vertex_ai-image-models": MappingProxyType(
+ {"vertex_project": "cc-scripted-project", "vertex_location": "us-central1"}
+ ),
+ "vertex_ai-embedding-models": MappingProxyType(
+ {"vertex_project": "cc-scripted-project", "vertex_location": "us-central1"}
+ ),
"gemini": MappingProxyType({}),
"together_ai": MappingProxyType({}),
"fireworks_ai": MappingProxyType({}),
diff --cc tests/integration/cost_calculation/cost_tracking_cases.json
index be0d62d360a,162d52648eb..3ef2f477ebd
--- a/tests/integration/cost_calculation/cost_tracking_cases.json
+++ b/tests/integration/cost_calculation/cost_tracking_cases.json
@@@ -409,88 -409,97 +409,180 @@@
"output_cost_per_token": 3.6e-06,
"supports_function_calling": true
},
+ "whisper-next": {
+ "litellm_provider": "openai",
+ "mode": "audio_transcription",
+ "input_cost_per_second": 0.0001
+ },
+ "whisper-verbose-next": {
+ "litellm_provider": "openai",
+ "mode": "audio_transcription",
+ "input_cost_per_second": 0.0002
+ },
+ "gpt-4o-transcribe-next": {
+ "litellm_provider": "openai",
+ "mode": "audio_transcription",
+ "input_cost_per_token": 2.11e-06,
+ "output_cost_per_token": 3.11e-06,
+ "input_cost_per_audio_token": 1e-05
+ },
+ "nova-next": {
+ "litellm_provider": "deepgram",
+ "mode": "audio_transcription",
+ "input_cost_per_second": 0.0003
+ },
+ "azure/whisper-next": {
+ "litellm_provider": "azure",
+ "mode": "audio_transcription",
+ "input_cost_per_second": 0.00011
+ },
+ "tts-next": {
+ "litellm_provider": "openai",
+ "mode": "audio_speech",
+ "input_cost_per_character": 1e-05
+ },
+ "tts-next-hd": {
+ "litellm_provider": "openai",
+ "mode": "audio_speech",
+ "input_cost_per_character": 2e-05
+ },
+ "azure/tts-next": {
+ "litellm_provider": "azure",
+ "mode": "audio_speech",
+ "input_cost_per_character": 1.1e-05
+ },
+ "gpt-image-next": {
+ "litellm_provider": "openai",
+ "mode": "image_generation",
+ "input_cost_per_token": 1.71e-06,
+ "output_cost_per_token": 4.3e-06,
+ "input_cost_per_image_token": 2.2e-06,
+ "output_cost_per_image_token": 5.1e-06
+ },
+ "1024-x-1024/dall-e-3-next": {
+ "litellm_provider": "openai",
+ "mode": "image_generation",
+ "input_cost_per_image": 0.04
+ },
+ "hd/1024-x-1024/dall-e-3-next": {
+ "litellm_provider": "openai",
+ "mode": "image_generation",
+ "input_cost_per_image": 0.08
+ },
+ "1792-x-1024/dall-e-3-next": {
+ "litellm_provider": "openai",
+ "mode": "image_generation",
+ "input_cost_per_image": 0.06
+ },
+ "low/1024-x-1024/gpt-image-next": {
+ "litellm_provider": "openai",
+ "mode": "image_generation",
+ "input_cost_per_token": 1.7e-06,
+ "output_cost_per_token": 4.3e-06,
+ "input_cost_per_image_token": 2.2e-06,
+ "output_cost_per_image_token": 5.1e-06
+ },
+ "1024-x-1024/imagen-next": {
+ "litellm_provider": "vertex_ai-image-models",
+ "mode": "image_generation",
+ "output_cost_per_image": 0.05
+ },
+ "amazon.nova-canvas-next": {
+ "litellm_provider": "bedrock",
+ "mode": "image_generation",
+ "output_cost_per_image": 0.045
++ },
+ "text-embedding-4-small": {
+ "input_cost_per_token": 1.01e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "openai",
+ "mode": "embedding"
+ },
+ "text-embedding-3-large-next": {
+ "input_cost_per_token": 1.02e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "openai",
+ "mode": "embedding"
+ },
+ "azure/text-embedding-4-large": {
+ "input_cost_per_token": 1.03e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "azure",
+ "mode": "embedding"
+ },
+ "embed-v5": {
+ "input_cost_per_token": 1.04e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "cohere",
+ "mode": "embedding"
+ },
+ "amazon.titan-embed-text-v2:0": {
+ "input_cost_per_token": 1.05e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "bedrock",
+ "mode": "embedding"
+ },
+ "cohere.embed-english-v4": {
+ "input_cost_per_token": 1.06e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "bedrock",
+ "mode": "embedding"
+ },
+ "text-embedding-006": {
+ "input_cost_per_token": 1.07e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "vertex_ai-embedding-models",
+ "mode": "embedding"
+ },
+ "gemini/gemini-embedding-002": {
+ "input_cost_per_token": 1.08e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "gemini",
+ "mode": "embedding"
+ },
+ "together_ai/together-embed-v1": {
+ "input_cost_per_token": 1.09e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "together_ai",
+ "mode": "embedding"
+ },
+ "fireworks_ai/fireworks-embed-v1": {
+ "input_cost_per_token": 1.1e-06,
+ "output_cost_per_token": 0,
+ "litellm_provider": "fireworks_ai",
+ "mode": "embedding"
+ },
+ "rerank-v4": {
+ "input_cost_per_token": 1.11e-06,
+ "output_cost_per_token": 0,
+ "input_cost_per_query": 0.0021,
+ "litellm_provider": "cohere",
+ "mode": "rerank"
+ },
+ "cohere.rerank-v4:0": {
+ "input_cost_per_token": 1.12e-06,
+ "output_cost_per_token": 0,
+ "input_cost_per_query": 0.0022,
+ "litellm_provider": "bedrock",
+ "mode": "rerank"
+ },
+ "gpt-3.5-turbo-instruct-next": {
+ "input_cost_per_token": 1.14e-06,
+ "output_cost_per_token": 2.14e-06,
+ "litellm_provider": "text-completion-openai",
+ "mode": "completion"
+ },
+ "omni-moderation-next": {
+ "input_cost_per_token": null,
+ "output_cost_per_token": 0,
+ "litellm_provider": "openai",
+ "mode": "moderation"
+ },
+ "together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo": {
+ "input_cost_per_token": 1.16e-06,
+ "output_cost_per_token": 2.16e-06,
+ "litellm_provider": "together_ai",
+ "mode": "completion"
}
},
"cases": [
@@@ -25861,520 -25870,851 +25953,1365 @@@
"completion_tokens": 412
}
},
+ {
+ "name": "whisper-next-transcriptions-per-second",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "whisper-next",
+ "endpoint": "/v1/audio/transcriptions",
+ "upload": {
+ "kind": "wav",
+ "seconds": 3.5
+ },
+ "request": {
+ "language": "en",
+ "response_format": "json"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "text": "hello"
+ }
+ },
+ "expected": {
+ "spend": 0.00035,
+ "input_cost": 0.00035,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "whisper-verbose-next-transcriptions-duration",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "whisper-verbose-next",
+ "endpoint": "/v1/audio/transcriptions",
+ "upload": {
+ "kind": "wav",
+ "seconds": 3.5
+ },
+ "request": {
+ "response_format": "verbose_json"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "text": "hello",
+ "duration": 12.25
+ }
+ },
+ "expected": {
+ "spend": 0.00245,
+ "input_cost": 0.00245,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "gpt-4o-transcribe-next-transcriptions-tokens",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "gpt-4o-transcribe-next",
+ "endpoint": "/v1/audio/transcriptions",
+ "upload": {
+ "kind": "wav",
+ "seconds": 1.0
+ },
+ "request": {
+ "response_format": "json"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "text": "hello",
+ "usage": {
+ "type": "tokens",
+ "input_tokens": 10,
+ "output_tokens": 2,
+ "total_tokens": 12,
+ "input_token_details": {
+ "text_tokens": 2,
+ "audio_tokens": 8
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 9.044e-05,
+ "input_cost": 8.422e-05,
+ "output_cost": 6.22e-06,
+ "prompt_tokens": 10,
+ "completion_tokens": 2
+ }
+ },
+ {
+ "name": "nova-next-transcriptions-per-second",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "nova-next",
+ "endpoint": "/v1/audio/transcriptions",
+ "upload": {
+ "kind": "wav",
+ "seconds": 4.0
+ },
+ "request": {},
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "results": {
+ "channels": [
+ {
+ "alternatives": [
+ {
+ "transcript": "hello",
+ "confidence": 0.9
+ }
+ ]
+ }
+ ]
+ },
+ "metadata": {
+ "duration": 4.0,
+ "channels": 1
+ }
+ }
+ },
+ "expected": {
+ "spend": 0.0012,
+ "input_cost": 0.0012,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "azure-whisper-next-transcriptions-deployment",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "azure/whisper-next",
+ "endpoint": "/v1/audio/transcriptions",
+ "deployment": {
+ "model": "azure/cc-whisper-deployment",
+ "base_model": "azure/whisper-next"
+ },
+ "upload": {
+ "kind": "wav",
+ "seconds": 3.5
+ },
+ "request": {
+ "response_format": "json"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "text": "hello"
+ }
+ },
+ "expected": {
+ "spend": 0.000385,
+ "input_cost": 0.000385,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "tts-next-speech-per-character",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "tts-next",
+ "endpoint": "/v1/audio/speech",
+ "request": {
+ "input": "hello world",
+ "voice": "alloy",
+ "response_format": "mp3"
+ },
+ "response": {
+ "content_type": "audio/mpeg",
+ "length": 2048
+ },
+ "expected": {
+ "spend": 0.0001,
+ "input_cost": 0.0001,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "tts-next-hd-speech-per-character",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "tts-next-hd",
+ "endpoint": "/v1/audio/speech",
+ "request": {
+ "input": "hello world",
+ "voice": "alloy",
+ "response_format": "mp3"
+ },
+ "response": {
+ "content_type": "audio/mpeg",
+ "length": 2048
+ },
+ "expected": {
+ "spend": 0.0002,
+ "input_cost": 0.0002,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "azure-tts-next-speech-deployment",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "azure/tts-next",
+ "endpoint": "/v1/audio/speech",
+ "deployment": {
+ "model": "azure/cc-tts-deployment",
+ "base_model": "azure/tts-next"
+ },
+ "request": {
+ "input": "hello world",
+ "voice": "alloy",
+ "response_format": "mp3"
+ },
+ "response": {
+ "content_type": "audio/mpeg",
+ "length": 2048
+ },
+ "expected": {
+ "spend": 0.00011,
+ "input_cost": 0.00011,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "dall-e-3-next-images-standard",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "1024-x-1024/dall-e-3-next",
+ "endpoint": "/v1/images/generations",
+ "deployment": {
+ "model": "openai/dall-e-3-next"
+ },
+ "request": {
+ "prompt": "a deterministic square",
+ "size": "1024x1024",
+ "quality": "standard",
+ "n": 1
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "created": 1700000000,
+ "data": [
+ {
+ "url": "https://x/1.png"
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.04,
+ "input_cost": 0.04,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "dall-e-3-next-images-hd",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "hd/1024-x-1024/dall-e-3-next",
+ "endpoint": "/v1/images/generations",
+ "deployment": {
+ "model": "openai/dall-e-3-next"
+ },
+ "request": {
+ "prompt": "a deterministic square",
+ "size": "1024x1024",
+ "quality": "hd",
+ "n": 1
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "created": 1700000001,
+ "data": [
+ {
+ "url": "https://x/1.png"
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.08,
+ "input_cost": 0.08,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "dall-e-3-next-images-wide",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "1792-x-1024/dall-e-3-next",
+ "endpoint": "/v1/images/generations",
+ "deployment": {
+ "model": "openai/dall-e-3-next"
+ },
+ "request": {
+ "prompt": "a deterministic wide image",
+ "size": "1792x1024",
+ "quality": "standard",
+ "n": 1
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "created": 1700000002,
+ "data": [
+ {
+ "url": "https://x/1.png"
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.06,
+ "input_cost": 0.06,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "dall-e-3-next-images-two",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "1024-x-1024/dall-e-3-next",
+ "endpoint": "/v1/images/generations",
+ "deployment": {
+ "model": "openai/dall-e-3-next"
+ },
+ "request": {
+ "prompt": "two deterministic squares",
+ "size": "1024x1024",
+ "quality": "standard",
+ "n": 2
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "created": 1700000003,
+ "data": [
+ {
+ "url": "https://x/1.png"
+ },
+ {
+ "url": "https://x/2.png"
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.08,
+ "input_cost": 0.08,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "gpt-image-next-images-low",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "gpt-image-next",
+ "endpoint": "/v1/images/generations",
+ "deployment": {
+ "model": "openai/gpt-image-next"
+ },
+ "request": {
+ "prompt": "a deterministic generated image",
+ "size": "1024x1024",
+ "quality": "low",
+ "n": 1
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "created": 1700000004,
+ "data": [
+ {
+ "b64_json": "AA=="
+ }
+ ],
+ "usage": {
+ "total_tokens": 30,
+ "input_tokens": 10,
+ "output_tokens": 20,
+ "input_tokens_details": {
+ "text_tokens": 10,
+ "image_tokens": 0
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 0.0001191,
+ "input_cost": 1.71e-05,
+ "output_cost": 0.000102,
+ "prompt_tokens": 10,
+ "completion_tokens": 20,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "imagen-next-images-one",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "1024-x-1024/imagen-next",
+ "endpoint": "/v1/images/generations",
+ "request": {
+ "prompt": "a deterministic vertex image",
+ "sampleCount": 1
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "predictions": [
+ {
+ "bytesBase64Encoded": "AA==",
+ "mimeType": "image/png"
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.05,
+ "input_cost": 0.05,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "amazon-nova-canvas-next-images-one",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "amazon.nova-canvas-next",
+ "endpoint": "/v1/images/generations",
+ "deployment": {
+ "model": "amazon.nova-canvas-next"
+ },
+ "request": {
+ "prompt": "a deterministic bedrock image"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "images": [
+ "AA=="
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.045,
+ "input_cost": 0.045,
+ "output_cost": 0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "gpt-image-next-images-edit",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "low/1024-x-1024/gpt-image-next",
+ "endpoint": "/v1/images/edits",
+ "deployment": {
+ "model": "openai/gpt-image-next"
+ },
+ "upload": {
+ "kind": "png"
+ },
+ "request": {
+ "prompt": "edit this deterministic image",
+ "size": "1024x1024",
+ "quality": "low",
+ "n": 1
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "created": 1700000005,
+ "data": [
+ {
+ "b64_json": "AA=="
+ }
+ ],
+ "usage": {
+ "total_tokens": 30,
+ "input_tokens": 10,
+ "output_tokens": 20,
+ "input_tokens_details": {
+ "text_tokens": 10,
+ "image_tokens": 0
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 0.000119,
+ "input_cost": 1.7e-05,
+ "output_cost": 0.000102,
+ "prompt_tokens": 10,
+ "completion_tokens": 20,
+ "breakdown_persisted": false
+ }
+ },
+ {
+ "name": "text-embeddings-4-small-single",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "text-embedding-4-small",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "one embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ }
+ ],
+ "model": "text-embedding-4-small",
+ "usage": {
+ "prompt_tokens": 7,
+ "total_tokens": 7
+ }
+ }
+ },
+ "expected": {
+ "spend": 7.07e-06,
+ "input_cost": 7.07e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 7,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "text-embeddings-4-small-batch",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "text-embedding-4-small",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": [
+ "one",
+ "two",
+ "three"
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ },
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 1
+ },
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 2
+ }
+ ],
+ "model": "text-embedding-4-small",
+ "usage": {
+ "prompt_tokens": 21,
+ "total_tokens": 21
+ }
+ }
+ },
+ "expected": {
+ "spend": 2.1210000000000002e-05,
+ "input_cost": 2.1210000000000002e-05,
+ "output_cost": 0.0,
+ "prompt_tokens": 21,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "text-embeddings-4-small-token-array",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "text-embedding-4-small",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": [
+ 1,
+ 2,
+ 3,
+ 4
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ }
+ ],
+ "model": "text-embedding-4-small",
+ "usage": {
+ "prompt_tokens": 9,
+ "total_tokens": 9
+ }
+ }
+ },
+ "expected": {
+ "spend": 9.090000000000001e-06,
+ "input_cost": 9.090000000000001e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 9,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "text-embeddings-3-large-dimensions",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "text-embedding-3-large-next",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "large embedding",
+ "dimensions": 3
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ }
+ ],
+ "model": "text-embedding-3-large-next",
+ "usage": {
+ "prompt_tokens": 8,
+ "total_tokens": 8
+ }
+ }
+ },
+ "expected": {
+ "spend": 8.16e-06,
+ "input_cost": 8.16e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 8,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "azure-text-embeddings-4-large-deployment",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "azure/text-embedding-4-large",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "azure embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ }
+ ],
+ "model": "azure/text-embedding-4-large",
+ "usage": {
+ "prompt_tokens": 8,
+ "total_tokens": 8
+ }
+ }
+ },
+ "expected": {
+ "spend": 8.24e-06,
+ "input_cost": 8.24e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 8,
+ "completion_tokens": 0
+ },
+ "deployment": {
+ "model": "azure/cc-pinned-embedding-deployment",
+ "base_model": "azure/text-embedding-4-large"
+ }
+ },
+ {
+ "name": "cohere-embeddings-v5",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "embed-v5",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "cohere embedding",
+ "input_type": "search_query"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "emb-1",
+ "embeddings": {
+ "float": [
+ [
+ 0.1,
+ 0.2,
+ 0.3
+ ]
+ ]
+ },
+ "meta": {
+ "billed_units": {
+ "input_tokens": 11
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 1.144e-05,
+ "input_cost": 1.144e-05,
+ "output_cost": 0.0,
+ "prompt_tokens": 11,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "bedrock-embeddings-titan-v2",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "amazon.titan-embed-text-v2:0",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "titan embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "inputTextTokenCount": 10
+ }
+ },
+ "expected": {
+ "spend": 1.05e-05,
+ "input_cost": 1.05e-05,
+ "output_cost": 0.0,
+ "prompt_tokens": 10,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "bedrock-cohere-embeddings-v4",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "cohere.embed-english-v4",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "bedrock cohere embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "embeddings": [
+ [
+ 0.1,
+ 0.2,
+ 0.3
+ ]
+ ],
+ "id": "emb-bedrock-cohere-1",
+ "response_type": "embeddings_floats",
+ "texts": [
+ "bedrock cohere embedding"
+ ]
+ }
+ },
+ "expected": {
+ "spend": 5.3e-06,
+ "input_cost": 5.3e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 5,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "vertex-embeddings-text-006",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "text-embedding-006",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "vertex embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "predictions": [
+ {
+ "embeddings": {
+ "values": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "statistics": {
+ "token_count": 7,
+ "truncated": false
+ }
+ }
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 7.4899999999999994e-06,
+ "input_cost": 7.4899999999999994e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 7,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "gemini-embeddings-002",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "gemini/gemini-embedding-002",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "gemini embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "embeddings": [
+ {
+ "values": [
+ 0.1,
+ 0.2,
+ 0.3
+ ]
+ }
+ ],
+ "usageMetadata": {
+ "promptTokenCount": 7,
+ "totalTokenCount": 7
+ }
+ }
+ },
+ "expected": {
+ "spend": 3.24e-06,
+ "input_cost": 3.24e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 3,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "together-embeddings-v1",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "together_ai/together-embed-v1",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "together embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ }
+ ],
+ "model": "together-embed-v1",
+ "usage": {
+ "prompt_tokens": 7,
+ "total_tokens": 7
+ }
+ }
+ },
+ "expected": {
+ "spend": 7.63e-06,
+ "input_cost": 7.63e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 7,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "fireworks-embeddings-v1",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "fireworks_ai/fireworks-embed-v1",
+ "endpoint": "/v1/embeddings",
+ "request": {
+ "model": "$MODEL",
+ "input": "fireworks embedding"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "object": "list",
+ "data": [
+ {
+ "object": "embedding",
+ "embedding": [
+ 0.1,
+ 0.2,
+ 0.3
+ ],
+ "index": 0
+ }
+ ],
+ "model": "fireworks-embed-v1",
+ "usage": {
+ "prompt_tokens": 7,
+ "total_tokens": 7
+ }
+ }
+ },
+ "expected": {
+ "spend": 7.7e-06,
+ "input_cost": 7.7e-06,
+ "output_cost": 0.0,
+ "prompt_tokens": 7,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "cohere-rerank-v4-one",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "rerank-v4",
+ "endpoint": "/v1/rerank",
+ "request": {
+ "model": "$MODEL",
+ "query": "rank this",
+ "documents": [
+ "a",
+ "b"
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "rr-$REQUEST_ID",
+ "results": [
+ {
+ "index": 0,
+ "relevance_score": 0.9
+ }
+ ],
+ "meta": {
+ "api_version": {
+ "version": "2"
+ },
+ "billed_units": {
+ "search_units": 1
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 0.0021,
+ "input_cost": 0.0021,
+ "output_cost": 0.0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "cohere-rerank-v4-three",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "rerank-v4",
+ "endpoint": "/v1/rerank",
+ "request": {
+ "model": "$MODEL",
+ "query": "rank this",
+ "documents": [
+ "a long document",
+ "another long document",
+ "third long document"
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "rr-three-$REQUEST_ID",
+ "results": [
+ {
+ "index": 0,
+ "relevance_score": 0.9
+ }
+ ],
+ "meta": {
+ "api_version": {
+ "version": "2"
+ },
+ "billed_units": {
+ "search_units": 3
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 0.0063,
+ "input_cost": 0.0063,
+ "output_cost": 0.0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "cohere-rerank-v4-total-tokens-fallback",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "rerank-v4",
+ "endpoint": "/v1/rerank",
+ "request": {
+ "model": "$MODEL",
+ "query": "rank this",
+ "documents": [
+ "fallback a",
+ "fallback b"
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "rr-fallback-$REQUEST_ID",
+ "results": [
+ {
+ "index": 0,
+ "relevance_score": 0.8
+ }
+ ],
+ "meta": {
+ "billed_units": {
+ "total_tokens": 99
+ }
+ }
+ }
+ },
+ "expected": {
+ "spend": 0.0,
+ "input_cost": 0.0,
+ "output_cost": 0.0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "bedrock-cohere-rerank-v4",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "cohere.rerank-v4:0",
+ "endpoint": "/v1/rerank",
+ "request": {
+ "model": "$MODEL",
+ "query": "rank this",
+ "documents": [
+ "a",
+ "b"
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "results": [
+ {
+ "index": 0,
+ "relevanceScore": 0.9
+ }
+ ],
+ "response_id": "rr-3",
+ "token_count": 1
+ }
+ },
+ "expected": {
+ "spend": 0.0022,
+ "input_cost": 0.0022,
+ "output_cost": 0.0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "text-completions-openai-basic",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "gpt-3.5-turbo-instruct-next",
+ "endpoint": "/v1/completions",
+ "request": {
+ "model": "$MODEL",
+ "prompt": "complete this"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "cmpl-basic-$REQUEST_ID",
+ "object": "text_completion",
+ "choices": [
+ {
+ "text": "done",
+ "index": 0,
+ "finish_reason": "stop"
+ }
+ ],
+ "usage": {
+ "prompt_tokens": 9,
+ "completion_tokens": 4,
+ "total_tokens": 13
+ }
+ }
+ },
+ "expected": {
+ "spend": 1.882e-05,
+ "input_cost": 1.026e-05,
+ "output_cost": 8.56e-06,
+ "prompt_tokens": 9,
+ "completion_tokens": 4
+ }
+ },
+ {
+ "name": "text-completions-openai-stream-usage",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "gpt-3.5-turbo-instruct-next",
+ "endpoint": "/v1/completions",
+ "request": {
+ "model": "$MODEL",
+ "prompt": "complete this",
+ "stream": true,
+ "stream_options": {
+ "include_usage": true
+ }
+ },
+ "response": {
+ "content_type": "text/event-stream",
+ "frames": [
+ "data: {\"id\": \"cmpl-$REQUEST_ID\", \"object\": \"text_completion\", \"created\": 1789789000, \"model\": \"gpt-3.5-turbo-instruct-next\", \"choices\": [{\"text\": \"done\", \"index\": 0, \"finish_reason\": null}], \"usage\": null}",
+ "data: {\"id\": \"cmpl-$REQUEST_ID\", \"object\": \"text_completion\", \"created\": 1789789000, \"model\": \"gpt-3.5-turbo-instruct-next\", \"choices\": [], \"usage\": {\"prompt_tokens\": 9, \"completion_tokens\": 4, \"total_tokens\": 13}}",
+ "data: [DONE]"
+ ]
+ },
+ "expected": {
+ "spend": 1.882e-05,
+ "input_cost": 1.026e-05,
+ "output_cost": 8.56e-06,
+ "prompt_tokens": 9,
+ "completion_tokens": 4
+ }
+ },
+ {
+ "name": "text-completions-openai-n-best",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "gpt-3.5-turbo-instruct-next",
+ "endpoint": "/v1/completions",
+ "request": {
+ "model": "$MODEL",
+ "prompt": "complete this twice",
+ "n": 2
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "cmpl-n-best-$REQUEST_ID",
+ "object": "text_completion",
+ "choices": [
+ {
+ "text": "done",
+ "index": 0,
+ "finish_reason": "stop"
+ },
+ {
+ "text": "also done",
+ "index": 1,
+ "finish_reason": "stop"
+ }
+ ],
+ "usage": {
+ "prompt_tokens": 9,
+ "completion_tokens": 8,
+ "total_tokens": 17
+ }
+ }
+ },
+ "expected": {
+ "spend": 2.738e-05,
+ "input_cost": 1.026e-05,
+ "output_cost": 1.712e-05,
+ "prompt_tokens": 9,
+ "completion_tokens": 8
+ }
+ },
+ {
+ "name": "together-completions-v1",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo",
+ "endpoint": "/v1/completions",
+ "request": {
+ "model": "$MODEL",
+ "prompt": "together complete"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "cmpl-together-$REQUEST_ID",
+ "object": "text_completion",
+ "choices": [
+ {
+ "text": "done",
+ "index": 0,
+ "finish_reason": "stop"
+ }
+ ],
+ "usage": {
+ "prompt_tokens": 9,
+ "completion_tokens": 4,
+ "total_tokens": 13
+ }
+ }
+ },
+ "expected": {
+ "spend": 1.908e-05,
+ "input_cost": 1.0439999999999998e-05,
+ "output_cost": 8.64e-06,
+ "prompt_tokens": 9,
+ "completion_tokens": 4
+ }
+ },
+ {
+ "name": "omni-moderations-next-single",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "omni-moderation-next",
+ "endpoint": "/v1/moderations",
+ "request": {
+ "model": "$MODEL",
+ "input": "safe text"
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "modr-single-$REQUEST_ID",
+ "model": "omni-moderation-next",
+ "results": [
+ {
+ "flagged": false,
+ "categories": {},
+ "category_scores": {}
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.0,
+ "input_cost": 0.0,
+ "output_cost": 0.0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
+ {
+ "name": "omni-moderations-next-list",
+ "covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
+ "model": "omni-moderation-next",
+ "endpoint": "/v1/moderations",
+ "request": {
+ "model": "$MODEL",
+ "input": [
+ "safe text",
+ "more safe text"
+ ]
+ },
+ "response": {
+ "content_type": "application/json",
+ "body": {
+ "id": "modr-list-$REQUEST_ID",
+ "model": "omni-moderation-next",
+ "results": [
+ {
+ "flagged": false,
+ "categories": {},
+ "category_scores": {}
+ },
+ {
+ "flagged": false,
+ "categories": {},
+ "category_scores": {}
+ }
+ ]
+ }
+ },
+ "expected": {
+ "spend": 0.0,
+ "input_cost": 0.0,
+ "output_cost": 0.0,
+ "prompt_tokens": 0,
+ "completion_tokens": 0
+ }
+ },
{
"name": "gpt-5.6-responses_cache_read",
"covers": "quota_management.spend_tracking.cost_matrix.logs_cost",
diff --cc tests/integration/cost_calculation/test_cost_tracking.py
index f6547406827,e31b0131b27..32ecd573363
--- a/tests/integration/cost_calculation/test_cost_tracking.py
+++ b/tests/integration/cost_calculation/test_cost_tracking.py
@@@ -212,15 -92,13 +212,19 @@@ def test_case_bills_expected_cost(gatew
return
expected: Final = case.expected
assert isinstance(expected, ExactExpected)
- if case.response.content_type == "application/json":
+ if isinstance(case.response, BinaryResponse):
+ header: Final = response.headers.get("x-litellm-response-cost")
+ if header is not None:
+ assert approx_equal(float(header), expected.spend), (
+ f"{case.name}: x-litellm-response-cost {header} != expected {expected.spend}"
+ )
+ elif case.response.content_type == "application/json":
header: Final = cast(str | None, response.headers.get("x-litellm-response-cost"))
- assert header is not None and approx_equal(float(header), expected.spend), (
+ assert (
+ (header is None or approx_equal(float(header), 0.0))
+ if expected.spend == 0
+ else (header is not None and approx_equal(float(header), expected.spend))
+ ), (
f"{case.name}: x-litellm-response-cost {header} != expected {expected.spend}"
)
assert row.spend is not None and approx_equal(row.spend, expected.spend), (