`api_image_request` logs and propagates the raw error response body, leaking the request's API key on 401
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start with docling/utils/api_image_request.py, especially the non-2xx logging and failure paths, streaming errors, and _parse_response_json; then trace how VlmPipeline reports failures. Check whether response bodies can contain credentials and run the relevant tests for these request paths. Done means errors and logs no longer expose API keys while still giving useful failure details.
Written by the indexing model from the issue text.
Description
Bug
When a remote VLM call fails, docling/utils/api_image_request.py copies the raw response body into both the log and the error it returns. OpenAI-compatible endpoints echo the request's API key in their 401 body — OpenAI's answers "Incorrect API key provided: sk-..." — so a misconfigured or rotated key ends up in clear text in:
- The process logs —
api_image_requeston a non-2xx:
_log.error(
"Error calling the API. status=%s content_type=%s response=%r",
r.status_code, r.headers.get("content-type"), _response_preview(r.text),
)
api_image_request_streamingdoes the same ("Error calling the API in streaming mode. ..."), and_parse_response_jsonlogsresponse=%rfor a 2xx non-JSON body.- Application-facing error details — the same body is embedded in the returned failure:
return _failed_request(f"HTTP {r.status_code}: {_response_preview(r.text)}") - which
VlmPipelinecopies into the page'sErrorItem (error_message="VLM inference failed: HTTP 401: ..."), so it reachesConversionResult.errors— text that applications typically surface to their own callers or persist on failed jobs.
The 500-character _response_preview truncation does not help: typical keys fit well within it, and a truncated key prefix is still sensitive.
Steps to reproduce
from docling.datamodel.pipeline_options import VlmPipelineOptions
from docling.datamodel.pipeline_options_vlm_model import ApiVlmOptions, ResponseFormat
# point at any OpenAI-compatible endpoint with an invalid Bearer key, e.g. api.openai.com
# convert any PDF → the key appears verbatim in the ERROR log line and in each page's error_message
Docling version
2.146.0
Python version
3.12
- Dominant language
- Python
- Stars
- 71k
- Forks
- 5.4k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 161
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from docling-project/docling
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
docling-project/docling#5592 ·
Maintainers usually reply within 2 days
-
AFP: export_to_doctags() raises ZeroDivisionError because every page has size 0x0Possibly taken @Krushil-Dhankecha claimed this 12 days ago. Openbug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
docling-project/docling#5355 · 1 comment ·
Maintainers usually reply within 2 days
-
AsciiDoc: thematic breaks and page breaks are kept as text or turned into list itemsPossibly taken @sohailshk claimed this 12 days ago. Openasciidoc bug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
docling-project/docling#5331 · 1 comment ·
Maintainers usually reply within 2 days
-
Merged paragraph across pages of different heights: continuation bbox uses the first page's heightPossibly taken @galer1us claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docling-project/docling#5286 ·
Maintainers usually reply within 2 days
-
CSV: a custom delimiter in the sep= hint is rejectedPossibly taken @saiteja-018 claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docling-project/docling#5284 ·
Maintainers usually reply within 2 days
All issues in docling-project/docling
Similar issues
-
app: scripts status: backlog type: housekeeping
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
netbox-community/netbox-scripts#239 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
LmeSzinc/AzurLaneAutoScript#6194 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/graphon#443 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day