langchain-ai/langchain · error · ValueError
OpenAI Chat Completions does not support file URLs.
Error message
OpenAI Chat Completions does not support file URLs.
What it means
Raised when a file content block with a `url` key is formatted for the OpenAI Chat Completions API (`api="chat/completions"`). Chat Completions has no `file_url` input field — remote file URLs are only accepted by the newer Responses API, so the converter refuses rather than sending a request OpenAI would reject.
Source
Thrown at libs/core/langchain_core/messages/block_translators/openai.py:129
" in the content block, e.g.: {'type': 'file', 'mime_type': "
"'...', 'base64': '...', 'filename': 'my-file.pdf'}. "
"Using placeholder filename 'LC_AUTOGENERATED'.",
stacklevel=1,
)
formatted_block = {"type": "file", "file": file}
if api == "responses":
formatted_block = {"type": "input_file", **formatted_block["file"]}
elif block.get("source_type") == "id" or "file_id" in block:
# Handle v0 format (IDContentBlock): {"source_type": "id", "id": "...", ...}
# Handle v1 format (IDCB): {"file_id": "...", ...}
file_id = block["id"] if "source_type" in block else block["file_id"]
formatted_block = {"type": "file", "file": {"file_id": file_id}}
if api == "responses":
formatted_block = {"type": "input_file", **formatted_block["file"]}
elif "url" in block: # Intentionally do not check for source_type="url"
if api == "chat/completions":
error_msg = "OpenAI Chat Completions does not support file URLs."
raise ValueError(error_msg)
# Only supported by Responses API; return in that format
formatted_block = {"type": "input_file", "file_url": block["url"]}
else:
error_msg = "Keys base64, url, or file_id required for file blocks."
raise ValueError(error_msg)
elif block["type"] == "audio":
if "base64" in block or block.get("source_type") == "base64":
# Handle v0 format: {"source_type": "base64", "data": "...", ...}
# Handle v1 format: {"base64": "...", ...}
base64_data = block["data"] if "source_type" in block else block["base64"]
audio_format = block["mime_type"].split("/")[-1]
formatted_block = {
"type": "input_audio",
"input_audio": {"data": base64_data, "format": audio_format},
}
else:
error_msg = "Key base64 is required for audio blocks."View on GitHub (pinned to e32fa9a52e)
Solutions
- Switch to a Responses-API model binding so the URL is emitted as `input_file.file_url`
- Or download the file and send it as base64 with `mime_type` (e.g. `application/pdf`) on Chat Completions
- Or upload the file to OpenAI and reference it by `file_id` instead of URL
Example fix
# before
block = {"type": "file", "url": "https://example.com/doc.pdf"}
resp = chat_model.invoke([HumanMessage(content=[block])]) # Chat Completions -> ValueError
# after
import base64
b64 = base64.b64encode(requests.get(url).content).decode()
block = {"type": "file", "base64": b64, "mime_type": "application/pdf"} Defensive patterns
Strategy: validation
Validate before calling
def file_url_allowed(block: dict, api: str) -> bool:
if block.get("type") == "file" and "url" in block:
return api == "responses"
return True Try / catch
try:
out = convert_to_openai_data_block(block, api="chat/completions")
except ValueError as e:
if "does not support file URLs" in str(e):
out = convert_to_openai_data_block(download_to_b64(block), api="chat/completions")
else:
raise Prevention
- Know which OpenAI API surface your model binding targets before sending file URLs
- Standardize on base64 or file_id for Chat Completions file inputs
- Encapsulate file-block building in one helper that picks the right source per API
When it happens
Trigger: Sending a file block like `{"type": "file", "url": "https://..."}` through a Chat Completions model or calling `convert_to_openai_data_block(block, api="chat/completions")` on it.
Common situations: Switching an app between Responses and Chat Completions model bindings while keeping file-URL blocks; assuming the two OpenAI APIs share the same multimodal input schema; PDFs hosted on a CDN passed to `gpt-4o`-style chat models.
Related errors
- Keys base64, url, or file_id required for file blocks.
- mime_type key is required for base64 data.
- Unsupported source type. Only 'url' and 'base64' are support
- Key base64 is required for audio blocks.
- Block of type {block['type']} is not supported.
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/0753382c58453b76.
Report an issue: GitHub.