`api_image_request` logs and propagates the raw error response body, leaking the request's API key on 401

Open Beginner friendly
#5,486 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 2 days

@prassu017 is already working on this.

Since Nov 19, 2026.

  • #5487 by @prassu017 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
security

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 priority:critical
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:

  1. The process logs — api_image_request on 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),
)
  1. api_image_request_streaming does the same ("Error calling the API in streaming mode. ..."), and _parse_response_json logs response=%r for a 2xx non-JSON body.
  2. 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)}")
  3. which VlmPipeline copies into the page's ErrorItem (error_message="VLM inference failed: HTTP 401: ..."), so it reaches ConversionResult.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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docling-project/docling

All issues in docling-project/docling

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.