Inconsistent behavior with URL context limits

Docs say url context limit can handle 20 URLs at a time: https://ai.google.dev/gemini-api/docs/url-context#limitations

But I’m finding that even if I send 10 URLs in my prompt, the API would often return INVALID_ARGUMENT. Here’s an example:

<some instructions on what to do with the URLs. instructions don’t contain any URL themselves>

Format your output as a JSON object as follows, include NOTHING else in the output:

[
  {
    “url”: ,
    “title”: ,
    “category”: ,
    “topics”: [],
    “notes”: 
  }, …
]

URLs:
<10 URLs, one in each line>


Error 
Failed to enrich batch for URLs starting with https://www.amazon.in/Ultimate-Resource-Julian-Lincoln-Simon/dp/069109389X/ref=sr_1_1?keywords=the+ultimate+resource+julian+simon&qid=1560051194&s=gateway&sr=8-1?tag=maswe-21: 
14768 |                 },
14769 |             };
14770 |         }
14771 |         const errorMessage = JSON.stringify(errorBody);
14772 |         if (status >= 400 && status < 600) {
14773 |             const apiError = new ApiError({
^
ApiError: {“error”:{“code”:400,“message”:“Number of urls to lookup exceeds the limit (24 > 20). Please reduce the number of urls in the request.”,“status”:“INVALID_ARGUMENT”}}
status: 400,

Is it possible to more information from the model on what links it thinks it saw? Because there were exactly 10 URLs in my prompt, but the error says the model thought there were 24. I’d love to figure out exact what were those extra 14 URLs

Hello,

Welcome to the Forum!!

I attempted to reproduce this issue myself, but it is working fine on my end. I tested it by providing 10 URLs with a prompt requesting the specific JSON output format you described, and the API processed it correctly without triggering the limit error.

Could you please share the exact prompt or code snippet you are using? It would be helpful to see exactly how the URLs are formatted in the request to understand why the model is detecting 24 URLs instead of 10.

Thanks