docling-java icon indicating copy to clipboard operation
docling-java copied to clipboard

Error when using picture_description_api : Client sends ISO-8601 Duration for timeout but server expects numeric seconds

Open madhukargunda opened this issue 11 months ago • 10 comments

Issue Summary:

When using docling-serve-api + docling-server-client, the timeout parameter is automatically serialized as an ISO-8601 duration string (e.g., PT1M30S) .

When setting .timeout(Duration.ofSeconds(90)) in docling-server-client, the client serializes the timeout field as an ISO-8601 duration string (PT1M30S). The docling-serve backend expects this field to be a numeric value , so it fails with error Input should be a valid number. The client and server disagree on timeout format.

Expected Behavior: The client should serialize Duration to a numeric timeout (e.g., 90 seconds) or the server should accept ISO-8601 durations.

Actual Behavior: The server receives "PT1M30S" and fails to parse it as a float.

private PictureDescriptionApi pictureDescriptionApi() { return PictureDescriptionApi .builder() .url(URI.create("https://api.openai.com/v1/chat/completions")) .headers(Map.of(HttpHeaders.AUTHORIZATION, "Bearer ******************")) .params(Map.of("model", "gpt-5", "max_completion_tokens", 500)) .timeout(Duration.ofSeconds(90)) .prompt("Describe the image in four sentences. Be concise and accurate.") .build(); }

madhukargunda avatar Dec 07 '25 14:12 madhukargunda

Hi @madhukargunda! I'm Dosu and I’m helping the docling-serve team.

The server expects the timeout parameter as a numeric value in seconds (e.g., 90), not an ISO-8601 duration string like "PT1M30S"—this is enforced by the API schema and documented examples (source). Python-based clients and integration tests all use numeric seconds, so the mismatch is likely due to Java's default serialization of Duration as ISO-8601.

To fix this, convert your Duration to seconds before serialization—send an integer or float (e.g., 90), not a Duration object. If your client library auto-serializes Duration as ISO-8601, you may need to manually extract the seconds (e.g., duration.getSeconds()) and set that value in the payload.

There is no server-side support for ISO-8601 durations, and adding it would require explicit changes to the API schema and validation logic (source). This applies to all timeout fields in the API, so check other endpoints if you use non-Python clients.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about docling-java with Dosu Add Dosu to your team

dosubot[bot] avatar Dec 07 '25 14:12 dosubot[bot]

@dosu I have one follow-up challenge regarding the serve-api implementation.

In my case, the serialization and deserialization logic for the timeout field is fully encapsulated inside the PictureDescriptionApi class that comes from the docling-serve-api JAR. Since this class is generated and packaged as part of the docling-serve-api library, I don’t have any extension points where I can override or customize how the Duration is serialized.

Because the builder method .timeout(Duration) only accepts a Duration object, the client automatically serializes it into an ISO-8601 string (PT1M30S). There is currently no way for me to intercept this and convert it to a numeric value (e.g., 90 seconds) before it is sent to the server.

Given that:

The class is part of the shipped JAR It is annotation-driven and auto-generated There is no hook to provide a custom serializer The API requires a raw numeric value for timeout How should Java users handle this mismatch?

madhukargunda avatar Dec 07 '25 15:12 madhukargunda

There are no extension points or configuration options in the current Java client to change how the timeout is serialized—it's locked to ISO-8601 if you use the provided builder and Duration type. The server only accepts a numeric value in seconds (e.g., 90), not an ISO-8601 string, and will reject the latter with a validation error (docs).

The only practical workaround is to bypass the generated client for this field: use a lower-level HTTP client (like OkHttp or Java's HttpClient) to manually construct the JSON payload, setting the timeout as a numeric value. For example, instead of using the builder, create the JSON object yourself and POST it to the API endpoint. This ensures the timeout is sent as a number, not a string.

If you need to stick with the generated client, you would need a change in the codegen or library to allow numeric timeout values, or for the server to add ISO-8601 support. Until then, manual payload construction is the only reliable path.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about docling-java with Dosu Add Dosu to your team

dosubot[bot] avatar Dec 07 '25 15:12 dosubot[bot]

@edeandrea is this something which should be looked in docling-java or in other components?

dolfim-ibm avatar Dec 08 '25 07:12 dolfim-ibm

Hi @dolfim-ibm this issue probably belongs in https://github.com/docling-project/docling-java rather than here.

edeandrea avatar Dec 08 '25 13:12 edeandrea

Is it possible to move this issue to that repo? Or should I just create a linked issue?

Looking at the OpenAPI doc

Image

What time format does this represent? Seconds? Milliseconds? Minutes?

edeandrea avatar Dec 08 '25 13:12 edeandrea

Hi @madhukargunda I will fix this in https://github.com/docling-project/docling-java today. We were planning to do a release today anyways, so this should be included by tomorrow.

edeandrea avatar Dec 08 '25 13:12 edeandrea

@dolfim-ibm

Image

What time format does this represent? Seconds? Milliseconds? Minutes?

edeandrea avatar Dec 08 '25 13:12 edeandrea

@dolfim-ibm

What time format does this represent? Seconds? Milliseconds? Minutes?

Seconds

dolfim-ibm avatar Dec 08 '25 13:12 dolfim-ibm

@madhukargunda you could also use Jackson Mixins to override how the marshalling works.

Granted you shouldn't need to do that in this case (it's purely a bug), but in the short term you can work around it.

edeandrea avatar Dec 08 '25 16:12 edeandrea