Skip to content

Conversation

sp-aaflalo
Copy link

Title

Get the model information of OpenRouter model automatically

Relevant issues

Fixes #13653

Partially, I couldn't find the way to have LiteLLM use the usage.cost parameter to return the actual cost of the request.

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature

Changes

Make the mode_info provider use the OpenRouter API to get missing data automatically.

Copy link

vercel bot commented Aug 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Aug 18, 2025 6:30pm

@CLAassistant
Copy link

CLAassistant commented Aug 18, 2025

CLA assistant check
All committers have signed the CLA.

@sp-aaflalo sp-aaflalo changed the title Openrouter model OpenRouter model from API automatically Aug 18, 2025

# OpenRouter has an API endpoint to get model info
if custom_llm_provider == "openrouter":
model_info = _get_model_info_open_router(model_name=model.strip(custom_llm_provider + "/"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's dangerous to add a sync network call to a helper util which can be used across the repo.

It would be safer to allow a user to run a function - e.g. litellm.pull_openrouter_model_info() -> and call litellm.register_model() in there - to add the values to the model cost map.

this way litellm.get_model_info will just work, without any network calls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good point, I had a hard time figure out where this method should live, and I saw we already have similar code for huggingface.

I'll make those change as soon as I have the time.

Copy link
Author

@sp-aaflalo sp-aaflalo Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other possibility would be to fix : https://github.com/BerriAI/litellm/actions/workflows/auto_update_price_and_context_window.yml

This github action, I could make it that it commit directly to the main branch by itself on a daily basis if there are changes.

Here is the PR for that, it would be more aligned with the project:
#13816

Copy link
Contributor

@krrishdholakia krrishdholakia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor to have an opt in function to pull openrouter model info and update model cost map.

this is safer than adding a sync network call to a helper util

@sp-aaflalo
Copy link
Author

I've gone ahead and instead decided to update the GitHub action and the python script that scrape the data of open router models:
#13816

@sp-aaflalo
Copy link
Author

@krrishdholakia I think #13816 is a better solution since we rely on updating automatically the json file with model info.

@sp-aaflalo sp-aaflalo closed this Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Getting Cost directly from OpenRouter api call
3 participants