LiteLlm: ValueError for an http(s) PDF file_uri with openai/azure models, although LiteLLM can fetch and inline it
🔴 Required Information
Describe the Bug:
LiteLlm raises a ValueError for a file_data part whose file_uri is an http(s) URL (e.g. a PDF) when the model resolves to the openai or azure provider. It fails while building the request, before anything is sent:
ValueError: File URI `https://<redacted>/report.pdf` not supported for provider: openai.
_is_file_uri_supported (google/adk/models/lite_llm.py) only accepts an OpenAI file id for those providers, unless the model is known to be proxied. But for OpenAI chat completions LiteLLM already handles document URLs itself: it fetches the URL (with its SSRF validation and a size limit) and rewrites the block as base64 file_data (OpenAIGPTConfig._handle_pdf_url). ADK already lets http(s) image and video URLs through for these providers (the _is_http_url branch in _get_content); documents are the only case it refuses.
A second effect: the provider is inferred from the model name (_get_provider_from_model returns openai for anything starting with gpt- or o1). A model served through a LiteLLM proxy under such an alias, but without the litellm_proxy/ prefix, is therefore treated as direct OpenAI and hits the same error, even though the proxy would accept the URL. An alias like claude-sonnet served through the same proxy works, because no provider is inferred from its name.
Steps to Reproduce:
pip install google-adk(no API key or network access is needed).- Run the snippet under "Minimal Reproduction Code" below.
- It raises the
ValueErrorabove.
Expected Behavior:
The URL is forwarded to LiteLLM as {"type": "file", "file": {"file_id": "<url>", "format": "application/pdf"}}, as it is for the other providers, and LiteLLM inlines it. This is how http(s) image URLs already behave for openai.
Observed Behavior:
File ".../google/adk/models/lite_llm.py", line 2126, in _get_content
raise ValueError(
ValueError: File URI `https://<redacted>/report.pdf` not supported for provider: openai.
Environment Details:
- ADK Library Version (pip show google-adk): 2.14.1 (reproduced).
_is_file_uri_supportedonmainhas the same logic (checked by reading the source when v2.15.1 was the latest release; I did not run 2.15.1). - Desktop OS: macOS
- Python Version (python -V): 3.12.12
Model Information:
- Are you using LiteLLM: Yes (litellm 1.97.0)
- Which model is being used:
openai/gpt-4o(the same happens with any LiteLLM proxy alias starting withgpt-)
🟡 Optional Information
Regression: Not known.
Additional Context:
What LiteLLM does with the block ADK would send (litellm 1.97.0, OpenAI path only; tested against a local HTTP server with LiteLLM's SSRF guard bypassed for the test):
OpenAIGPTConfig().transform_request(
model="gpt-4o",
messages=[{"role": "user", "content": [
{"type": "text", "text": "Summarize this document."},
{"type": "file", "file": {"file_id": "http://127.0.0.1:PORT/doc.pdf", "format": "application/pdf"}},
]}],
optional_params={}, litellm_params={}, headers={},
)
# content[1]["file"] == {"file_data": "data:application/pdf;base64,JVBERi0x...", "filename": "my_file.pdf"}
Workarounds today: prefix the model with litellm_proxy/ or set USE_LITELLM_PROXY=true. Both make _is_proxied_model true, so the check passes. They only apply when the call really goes through a LiteLLM proxy.
Related: #4038, #4174, #5546, #6722.
Proposed fix: in _get_content, for providers in _FILE_ID_REQUIRED_PROVIDERS, treat an http(s) file_uri of a document like the existing image/video shortcut: do not raise, emit the file block and let LiteLLM fetch it. I only verified the OpenAI path in LiteLLM, so azure would need checking. Happy to send a PR with tests if this direction is acceptable.
Minimal Reproduction Code:
import asyncio
from google.adk.models import LiteLlm
from google.adk.models.llm_request import LlmRequest
from google.genai import types
request = LlmRequest(
contents=[
types.Content(
role="user",
parts=[
types.Part.from_text(text="Summarize this document."),
types.Part(
file_data=types.FileData(
file_uri="https://example.com/report.pdf",
mime_type="application/pdf",
)
),
],
)
]
)
async def main() -> None:
# No network is needed: it fails while building the request.
llm = LiteLlm(model="openai/gpt-4o")
async for _ in llm.generate_content_async(request):
pass
asyncio.run(main())
How often has this issue occurred?:
- Always (100%)
I'd like to work on this. The failure happens while building the request in _get_content, before any provider call: HTTP document URIs fall through the existing image/video URL shortcut and then fail _is_file_uri_supported for openai/azure.
The change I'd propose is to treat an http(s) document file_uri like those image/video URLs: emit {"type": "file", "file": {"file_id": "<url>", "format": "<mime>"}} and let LiteLLM fetch/inline it, while keeping the current OpenAI file-id behavior. I'll add unit tests under tests/unittests/.
Happy to hold off if you already have a patch in progress.