PaddlePaddle/PaddleOCR · error · InvalidRequestError

Either file_url or file_path is required.

Error message

Either file_url or file_path is required.

What it means

Raised as InvalidRequestError by validate_input_source() in _core.py when neither file_url nor file_path is supplied. Every file-submission API requires exactly one of the two, so the call is rejected before any network request is made. This is a client-side usage error, not a service failure.

Source

Thrown at paddleocr/_api_client/_core.py:40

    ResponseFormatError,
    ServiceUnavailableError,
)
from .models import (
    DocParsingOptions,
    Model,
    OCROptions,
    PaddleOCRVLOptions,
    PPStructureV3Options,
    is_document_parsing_model,
    is_ocr_model,
    is_vl_model,
)
from .results import BatchStatus, Job, JobStatus, Progress


def validate_input_source(file_url: Optional[str], file_path: Optional[str]) -> None:
    if not file_url and not file_path:
        raise InvalidRequestError("Either file_url or file_path is required.")
    if file_url and file_path:
        raise InvalidRequestError("file_url and file_path are mutually exclusive.")


def default_payload(model: Model) -> dict:
    if is_ocr_model(model):
        return OCROptions().to_payload()
    return resolve_document_options(model, None).to_payload()


def resolve_ocr_model(model: Union[Model, str]) -> Model:
    resolved = resolve_model(model)
    if not is_ocr_model(resolved):
        raise InvalidRequestError(f"Unsupported OCR model: {model}")
    return resolved


def resolve_document_model(model: Union[Model, str]) -> Model:

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Pass exactly one of file_url or file_path to the submission call.
  2. Check for typos in the keyword name (it is file_url / file_path).
  3. Assert the variable holding the path is set before calling.

Example fix

# before
job = await client.ocr(filepath="a.png")  # both args None -> InvalidRequestError

# after
job = await client.ocr(file_path="a.png")
Defensive patterns

Strategy: validation

Validate before calling

def ensure_input(file_url=None, file_path=None):
    if not file_url and not file_path:
        raise ValueError("provide file_url or file_path")
    if file_url and file_path:
        raise ValueError("provide only one of file_url / file_path")

ensure_input(file_url, file_path)
client.ocr(file_url=file_url, file_path=file_path)

Try / catch

from paddleocr._api_client.errors import InvalidRequestError
try:
    job = await client.ocr(file_path=path)
except InvalidRequestError as e:
    if "required" in str(e):
        # fill in the missing source argument
        ...

Prevention

When it happens

Trigger: Calling create-OCR or document-parsing methods with both file_url=None and file_path=None, e.g. passing only options/model or misspelling the keyword argument.

Common situations: Misspelled kwarg (file_path vs filepath), passing a Path-like variable that is None, or refactoring code that used to inline the path.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/0b58423889825b21. Report an issue: GitHub.