litellm/litellm
d 🔹 9d6983c4c0
fix(gemini): handle Gemini Files API URIs without fetching (#24922)
* fix(gemini): handle Gemini Files API URIs without fetching

Fixes #24907

When a file is uploaded via the Gemini Files API, the returned URI
(https://generativelanguage.googleapis.com/v1beta/files/...) starts
with 'https://' and hits the generic HTTPS handler in
_process_gemini_media(). That handler calls
_get_image_mime_type_from_url() which tries to fetch the URL — but
Gemini Files API URLs return 403 when accessed directly, causing:
  'Unable to determine mime type for file_id: ...'

Fix: add an early elif that matches Gemini Files API URLs and passes
them through as file_data without trying to fetch the URL. When an
explicit format is provided it's included; otherwise the Gemini API
infers the MIME type from its stored metadata.

Exactly matches the fix direction suggested by the issue reporter
(rodriciru).

* fix: anchor Gemini Files API URL check with startswith

Address greptile P2: replace `in` substring check with `startswith`
to prevent query-string injection bypass (e.g.
`https://evil.com/?ref=https://generativelanguage...`).

Also adds trailing slash to match only valid file URIs.

---------

Co-authored-by: voidborne-d <voidborne-d@users.noreply.github.com>
2026-05-01 17:26:45 +05:30
..
a2a_protocol feat(guardrails): LLM-as-a-Judge guardrail (#26360) 2026-04-24 17:15:32 -07:00
anthropic_interface style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
assistants
batch_completion fix: prompt registry 2026-02-18 00:34:54 +05:30
batches fix(proxy/batches): forward model to retrieve_batch for bedrock 2026-04-29 22:48:03 +02:00
caching Match docstring style on async_increment_cache 2026-04-30 17:50:58 -07:00
completion_extras Revert "Merge pull request #24417 from Chesars/refactor/shared-format-mapping" 2026-04-25 15:03:24 -03:00
compression Prompt Compression - add it to the proxy (#25729) 2026-04-20 15:08:00 -07:00
containers style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
endpoints/speech/speech_to_completion_bridge
evals style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
experimental_mcp_client refactor(mcp): reuse existing sessions for initialize instructions 2026-04-14 14:46:06 +03:00
files style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
fine_tuning address greptile review feedback (greploop iteration 1) 2026-03-27 20:04:41 +05:30
google_genai feat(proxy): LiteLLM headers on Google native generateContent routes (#25500) 2026-04-29 12:34:14 -07:00
images Feat(dashscope): add image generation support for qwen-image-2.0 and qwen-image-2.0-pro (#25672) 2026-04-22 20:03:46 -07:00
integrations fix: trim caller-supplied dicts from compile_prompt error message 2026-04-29 15:16:01 -07:00
interactions style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
litellm_core_utils fix(llm translation): redact Gemini API key from URL query params in error traces (#24943) 2026-05-01 17:24:43 +05:30
llms fix(gemini): handle Gemini Files API URIs without fetching (#24922) 2026-05-01 17:26:45 +05:30
ocr style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
passthrough fix(passthrough): log when streaming spend-tracking flush fails to schedule 2026-04-30 02:39:29 +00:00
proxy fix(proxy): include team membership budget in combined_view for RPM/TPM (#24925) 2026-05-01 17:26:45 +05:30
proxy_auth fix: prompt registry 2026-02-18 00:34:54 +05:30
rag style: black formatting 2026-04-25 14:47:54 -07:00
realtime_api Root cause fix - migrate all logging update to use 1 function - for centralized kwarg updates (#23659) 2026-03-15 23:21:01 -07:00
rerank_api Fix review 2026-04-30 09:10:24 +05:30
responses Revert "Merge pull request #24417 from Chesars/refactor/shared-format-mapping" 2026-04-25 15:03:24 -03:00
router_strategy add test(tag-routing): prevent header regex bypass for strict plain tags. 2026-04-29 20:14:30 +00:00
router_utils Merge pull request #26691 from BerriAI/litellm_team_search_credentials_metadata 2026-04-30 08:35:17 +05:30
search style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
secret_managers style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
skills style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
types feat: add Qohash Nexus guardrail hook (#24927) 2026-05-01 17:26:32 +05:30
vector_store_files Root cause fix - migrate all logging update to use 1 function - for centralized kwarg updates (#23659) 2026-03-15 23:21:01 -07:00
vector_stores style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
videos style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
__init__.py Merge pull request #26303 from BerriAI/litellm_internal_staging 2026-04-23 08:30:54 +05:30
_internal_context.py fix(proxy): harden request parameter handling 2026-04-16 01:38:12 +00:00
_lazy_imports.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
_lazy_imports_registry.py feat(bedrock): add support for bedrock-mantle endpoint (Claude Mythos Preview) (#26196) 2026-04-21 15:41:58 -07:00
_logging.py fix(llm translation): redact Gemini API key from URL query params in error traces (#24943) 2026-05-01 17:24:43 +05:30
_redis.py Litellm ishaan march23 - MCP Toolsets + GCP Caching fix (#25146) (#25155) 2026-04-04 16:23:21 -07:00
_redis_credential_provider.py fix(redis): cache GCP IAM token to prevent async event loop blocking (#26441) 2026-04-25 23:13:39 -07:00
_service_logger.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
_uuid.py
_version.py
anthropic_beta_headers_config.json Merge pull request #25867 from BerriAI/litellm_day_0_opus_4.7_support 2026-04-16 22:49:51 +05:30
anthropic_beta_headers_manager.py Refactor: Filtering beta header after transformation 2026-03-16 10:47:15 +05:30
blog_posts.json docs(blog): add WebRTC blog post link 2026-03-13 17:54:33 +05:30
budget_manager.py
constants.py Merge pull request #26835 from stuxf/codex/cli-sso-flow-binding 2026-04-30 17:10:27 -07:00
cost.json
cost_calculator.py fix(cost): pass service_tier through azure and azure_ai cost calculation (#24926) 2026-05-01 17:26:45 +05:30
exceptions.py fix(proxy): invoke post-call guardrails on pass-through endpoint responses (#20270) (#26262) 2026-04-27 08:58:22 +05:30
main.py Merge pull request #26745 from BerriAI/litellm_internal_staging 2026-04-29 09:25:42 +05:30
model_prices_and_context_window_backup.json fix(bedrock): add 1-hour cache write tier for Claude 4.5/4.6/4.7 (Global, US) 2026-04-29 19:21:57 +00:00
mypy.ini
policy_templates_backup.json feat(add-new-block_code_execution-guardrail): prevent agent from executing code (#22154) 2026-02-25 22:02:14 -08:00
provider_endpoints_support_backup.json Feature/add audio support for scaleway (#26110) 2026-04-20 14:49:41 -07:00
py.typed
router.py fix(router): propagate custom cost_per_token from db model_info in fallback path (#25888) 2026-04-27 08:58:41 +05:30
scheduler.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
setup_wizard.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
timeout.py
utils.py Add gpt-image-2 support (#26644) (#26705) 2026-04-28 20:10:42 -07:00