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]

fix(batches): sign the retrieve-path output read with the deployment's AWS credentials

mateo-berri1524880dceef
diff --git a/litellm/batches/batch_utils.py b/litellm/batches/batch_utils.py
index f7aa6c50de8..ebef60b41c9 100644
--- a/litellm/batches/batch_utils.py
+++ b/litellm/batches/batch_utils.py
@@ -5,6 +5,7 @@ from typing import Any, Final, Literal
import litellm
from litellm._logging import verbose_logger
+from litellm.litellm_core_utils.get_litellm_params import AWS_CREDENTIAL_KWARGS_KEYS
from litellm.litellm_core_utils.llm_cost_calc.utils import _parse_prompt_tokens_details
from litellm.types.llms.openai import Batch
from litellm.types.utils import CallTypes, ModelInfo, Usage
@@ -295,7 +296,7 @@ def _extract_file_access_credentials(litellm_params: dict | None) -> dict:
if litellm_params:
# List of credential keys that should be passed to file operations
- credential_keys: Final = [
+ credential_keys: Final = (
"api_key",
"api_base",
"api_version",
@@ -310,7 +311,8 @@ def _extract_file_access_credentials(litellm_params: dict | None) -> dict:
"timeout",
"max_retries",
"_litellm_internal_model_credentials",
- ]
+ *AWS_CREDENTIAL_KWARGS_KEYS,
+ )
for key in credential_keys:
if key in litellm_params:
credentials[key] = litellm_params[key]
diff --git a/tests/test_litellm/batches/test_batch_utils.py b/tests/test_litellm/batches/test_batch_utils.py
index cacae3624f3..d2074853f2b 100644
--- a/tests/test_litellm/batches/test_batch_utils.py
+++ b/tests/test_litellm/batches/test_batch_utils.py
@@ -1243,3 +1243,59 @@ def test_extract_credentials_forwards_the_trusted_model_credential_snapshot():
credentials = bu._extract_file_access_credentials({"_litellm_internal_model_credentials": snapshot})
assert credentials["_litellm_internal_model_credentials"] is snapshot
+
+
+def test_extract_credentials_forwards_the_deployment_aws_credentials():
+ """The retrieve path's logging object carries the deployment's AWS keys in its
+ litellm_params, and the S3 read of the output file signs with whatever afile_content
+ receives. Dropping them here sent the read to the ambient credential chain, so a
+ deployment whose only AWS credentials live in its litellm_params never recorded
+ batch cost on retrieve even once the bucket resolved."""
+ params = {
+ "aws_access_key_id": "AKIA-deployment",
+ "aws_secret_access_key": "secret-deployment",
+ "aws_session_token": "token-deployment",
+ "aws_region_name": "us-west-2",
+ "aws_role_name": "arn:aws:iam::123456789012:role/batch-reader",
+ "model": "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ }
+
+ credentials = bu._extract_file_access_credentials(params)
+
+ assert credentials == {key: value for key, value in params.items() if key != "model"}
+
+
+async def test_output_file_content_bedrock_reads_with_deployment_aws_credentials(monkeypatch):
+ import litellm.files.main as files_main
+
+ captured: dict = {}
+
+ async def fake_afile_content(**kw):
+ captured.update(kw)
+ return type("R", (), {"content": b""})()
+
+ monkeypatch.setattr(files_main, "afile_content", fake_afile_content)
+ snapshot = MappingProxyType({"s3_bucket_name": "configured-bucket", "aws_region_name": "us-west-2"})
+
+ await bu._fetch_batch_output_file_content(
+ _batch("s3://configured-bucket/litellm-batch-outputs/job-1/out.jsonl.out"),
+ custom_llm_provider="bedrock",
+ litellm_params={
+ "aws_access_key_id": "AKIA-deployment",
+ "aws_secret_access_key": "secret-deployment",
+ "aws_session_token": "token-deployment",
+ "aws_region_name": "us-west-2",
+ "_litellm_internal_model_credentials": snapshot,
+ "model": "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ },
+ )
+
+ assert captured["file_id"] == "s3://configured-bucket/litellm-batch-outputs/job-1/out.jsonl.out"
+ assert captured["custom_llm_provider"] == "bedrock"
+ assert captured["aws_access_key_id"] == "AKIA-deployment"
+ assert captured["aws_secret_access_key"] == "secret-deployment"
+ assert captured["aws_session_token"] == "token-deployment"
+ assert captured["aws_region_name"] == "us-west-2"
+ assert captured["_litellm_internal_model_credentials"] is snapshot
+ assert "model" not in captured