docling-project/docling · error · ValueError

Expected ApiVlmEngineOptions, got {type(options)}

Error message

Expected ApiVlmEngineOptions, got {type(options)}

What it means

create_vlm_engine validates the options/engine-type pairing for API variants (VlmEngineType.is_api_variant). API engines such as ApiVlmEngine require ApiVlmEngineOptions; any other options subclass raises this ValueError.

Source

Thrown at docling/models/inference_engines/vlm/factory.py:125

        from docling.models.inference_engines.vlm.vllm_engine import VllmVlmEngine

        if not isinstance(options, VllmVlmEngineOptions):
            raise ValueError(f"Expected VllmVlmEngineOptions, got {type(options)}")
        return VllmVlmEngine(
            options,
            model_config=model_config,
            artifacts_path=artifacts_path,
            accelerator_options=accelerator_options,
        )

    elif VlmEngineType.is_api_variant(engine_type):
        from docling.datamodel.vlm_engine_options import ApiVlmEngineOptions
        from docling.models.inference_engines.vlm.api_openai_compatible_engine import (
            ApiVlmEngine,
        )

        if not isinstance(options, ApiVlmEngineOptions):
            raise ValueError(f"Expected ApiVlmEngineOptions, got {type(options)}")
        return ApiVlmEngine(
            enable_remote_services=enable_remote_services,
            options=options,
            model_config=model_config,
        )

    else:
        raise ValueError(f"Unsupported engine type: {engine_type}")

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Construct ApiVlmEngineOptions (with url set) for API engine types
  2. If you meant a local runtime, keep the local options class and its matching engine_type
  3. Verify enable_remote_services is true when the endpoint is remote, since ApiVlmEngine receives that flag at creation

Example fix

# before
options = TransformersVlmEngineOptions(engine_type=VlmEngineType.API)
engine = create_vlm_engine(options=options, enable_remote_services=True, ...)

# after
from docling.datamodel.vlm_engine_options import ApiVlmEngineOptions
options = ApiVlmEngineOptions(url='http://localhost:8000/v1/chat/completions')
engine = create_vlm_engine(options=options, enable_remote_services=True, ...)
Defensive patterns

Strategy: type-guard

Validate before calling

from docling.datamodel.vlm_engine_options import ApiVlmEngineOptions
from docling.models.inference_engines.vlm.base import VlmEngineType

assert VlmEngineType.is_api_variant(options.engine_type)
assert isinstance(options, ApiVlmEngineOptions), (
    f'options/engine_type mismatch: {type(options).__name__}'
)

Type guard

from docling.datamodel.vlm_engine_options import ApiVlmEngineOptions

def is_api_options(opts: object) -> bool:
    return isinstance(opts, ApiVlmEngineOptions)

Try / catch

try:
    engine = create_vlm_engine(options=options, model_spec=spec, enable_remote_services=True, artifacts_path=None, accelerator_options=acc)
except ValueError as e:
    if 'Expected ApiVlmEngineOptions' in str(e):
        from docling.datamodel.vlm_engine_options import ApiVlmEngineOptions
        engine = create_vlm_engine(options=ApiVlmEngineOptions(url='http://localhost:8000/v1/chat/completions'), model_spec=spec, enable_remote_services=True, artifacts_path=None, accelerator_options=acc)
    else:
        raise

Prevention

When it happens

Trigger: Calling create_vlm_engine where VlmEngineType.is_api_variant(options.engine_type) is true (API engine types) but options is not ApiVlmEngineOptions — e.g. a local-runtime options class with its engine_type switched to the API variant.

Common situations: Moving from a local model to a hosted/local OpenAI-compatible endpoint and only changing engine_type; reusing Transformers options because they also have url-ish fields.

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/772d736e5c6c4618. Report an issue: GitHub.