Skip to content

TypeError exception on llm openrouter models #61

Open

Description

@castedo

REPRO STEP:

llm openrouter models

RESULT:

- id: inclusionai/ling-3.0-flash-vl:free
  name: inclusionAI: Ling 3.0 Flash VL (free)
  context_length: 262,144
  architecture:
    modality: text+image+video->text
    input_modalities: ["text", "image", "video"]
    output_modalities: ["text"]
    tokenizer: Other
    instruct_type: null
  supports_schema: False
  supports_tools: True

Traceback (most recent call last):
  File "<frozen runpy>", line 203, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.14/site-packages/llm/__main__.py", line 4, in <module>
    cli()
    ~~~^^
  File "/usr/lib/python3.14/site-packages/click/core.py", line 1514, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/click/core.py", line 1435, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.14/site-packages/click/core.py", line 1902, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/click/core.py", line 1902, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/click/core.py", line 1298, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/click/core.py", line 853, in invoke
    return callback(*args, **kwargs)
  File "/home/castedo/shr/src/ex/llm-openrouter/llm_openrouter.py", line 834, in models
    pricing = format_pricing(model["pricing"])
  File "/home/castedo/shr/src/ex/llm-openrouter/llm_openrouter.py", line 928, in format_pricing
    formatted_price = format_price(key, value)
  File "/home/castedo/shr/src/ex/llm-openrouter/llm_openrouter.py", line 874, in format_price
    price = float(price_str)
TypeError: float() argument must be a string or a real number, not 'list'

COMMENTARY:

The problem is an overrides key under pricing. From the json cached in

~/.config/io.datasette.llm/openrouter_models.json

here is an example of such data:

...
    {
      "id": "openai/gpt-6-astra",
...
      "pricing": {
        "prompt": "0.00001",
        "completion": "0.00005",
        "web_search": "0.01",
        "input_cache_read": "0.000001",
        "input_cache_write": "0.0000125",
        "overrides": [
          {
            "min_prompt_tokens": 272000,
            "prompt": "0.00002",
            "completion": "0.000075",
            "input_cache_read": "0.000002",
            "input_cache_write": "0.000025"
          }
        ]
      },
...

Based on
https://openrouter.ai/docs/api_reference/overview#openapi-specification
I made this quick fix that avoids the problem robustly:

diff --git a/llm_openrouter.py b/llm_openrouter.py
index 4b74c60..4e4d9d3 100644
--- a/llm_openrouter.py
+++ b/llm_openrouter.py
@@ -4,6 +4,8 @@ from copy import deepcopy
 from functools import cache
 from pathlib import Path
 from typing import Literal, Optional, Union
+from warnings import warn
+
 
 import click
 import httpx
@@ -905,6 +907,24 @@ def format_price(key, price_str):
 def format_pricing(pricing_dict):
     formatted_parts = []
     for key, value in pricing_dict.items():
+        if key not in (
+            "audio",
+            "audio_output",
+            "completion",
+            "image",
+            "image_output",
+            "image_token",
+            "input_audio_cache",
+            "input_cache_read",
+            "input_cache_write",
+            "input_cache_write_1h",
+            "internal_reasoning",
+            "prompt",
+            "request",
+            "web_search",
+        ):
+            warn(f"Ignoring unknown pricing key '{key}'")
+            continue
         formatted_price = format_price(key, value)
         if formatted_price:
             formatted_parts.append(formatted_price)

Do you want a PR for the above quick fix?

Activity

  1. castedo commented on Sep 21, 2026

    @castedo
    Author

    @simonw I do not recommend merging the PR #62 by @abhi-0203. I believe it is LLM generated with hallucinations and @abhi-0203 made little effort to read this issue submission by me. I think the PR is sloppy in just ignoring the price key and ignoring the exception, catching it, and ignoring the exception.

    I'm more than happy to create a PR myself if you think the approach I suggest in this bug issue makes sense. I'm also happy to communicate with humans on engineering a PR based on human thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions