PaddlePaddle/PaddleOCR · critical · AuthError

Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=

Error message

Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=.

What it means

AuthError raised by the synchronous PaddleOCRClient.__init__ when token= is empty/None and PADDLEOCR_ACCESS_TOKEN is unset. The client refuses to build without credentials so requests cannot silently go out unauthenticated.

Source

Thrown at paddleocr/_api_client/client.py:58


class PaddleOCRClient:
    """Synchronous blocking client for PaddleOCR official API.

    Wraps the async job API internally: submit → poll → fetch result.
    """

    def __init__(
        self,
        token: Optional[str] = None,
        base_url: Optional[str] = None,
        request_timeout: float = 300.0,
        poll_timeout: float = 600.0,
        client_platform: Optional[str] = None,
    ):
        self._token = token or os.environ.get("PADDLEOCR_ACCESS_TOKEN", "")
        if not self._token:
            raise AuthError(
                "Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=."
            )
        resolved_base_url = (
            base_url or os.environ.get("PADDLEOCR_BASE_URL") or DEFAULT_BASE_URL
        )
        self._http = HTTPClient(
            self._token,
            resolved_base_url,
            request_timeout,
            client_platform=client_platform,
        )
        self._poller = Poller(self._http, max_wait_time=poll_timeout)

    def __enter__(self):
        return self

    def __exit__(self, *args):
        self.close()

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Pass token= explicitly at construction
  2. Set PADDLEOCR_ACCESS_TOKEN in the launching environment (export, Dockerfile ENV, CI secret)
  3. Verify with a quick check: python -c "import os; print(bool(os.environ.get('PADDLEOCR_ACCESS_TOKEN')))"

Example fix

# before
client = PaddleOCRClient()
# after
client = PaddleOCRClient(token=get_token_from_secret_store())
Defensive patterns

Strategy: validation

Validate before calling

import os

assert os.environ.get('PADDLEOCR_ACCESS_TOKEN') or TOKEN_FROM_CONFIG, 'PaddleOCR token missing'

Try / catch

from paddleocr._api_client.errors import AuthError

try:
    client = PaddleOCRClient(token=tok)
except AuthError as e:
    log_and_alert(e)  # config problem, not transient
    raise

Prevention

When it happens

Trigger: PaddleOCRClient() constructed with no arguments in an environment lacking PADDLEOCR_ACCESS_TOKEN; token set in a different shell/session than the one running the code.

Common situations: Local scripts run from an IDE that does not inherit shell env vars; Docker images that drop env vars; CI pipelines missing the secret.

Related errors


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