Skip to content

Sync model names and costs via LiteLLM's registry#227

Merged
Ankur Goyal (ankrgyl) merged 9 commits intomainfrom
model-costs
May 19, 2025
Merged

Sync model names and costs via LiteLLM's registry#227
Ankur Goyal (ankrgyl) merged 9 commits intomainfrom
model-costs

Conversation

@ankrgyl
Copy link
Copy Markdown
Contributor

@ankrgyl Ankur Goyal (ankrgyl) commented May 17, 2025

Our friends at https://github.com/BerriAI/litellm maintain a great registry of model costs which we can reuse. This script helps us automatically keep things in sync.

To facilitate this, I moved the models into their own file. Note that this change does not include the application of any changes from this script. That's in a separate PR so we can clearly see what they are.

@vercel
Copy link
Copy Markdown

vercel bot commented May 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai-proxy ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2025 6:20pm

@ankrgyl Ankur Goyal (ankrgyl) changed the title wip: cached token costs Sync model names and costs via LiteLLM's registry May 17, 2025
Copy link
Copy Markdown
Collaborator

@ibolmo Olmo Maldonado (ibolmo) left a comment

Choose a reason for hiding this comment

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

mostly have nits but the more I think on it.. what if the problem could be simpler?

what if we used git diff:

converted = getLiteLLMModels()
models = translateToBraintrust(converted)  // all of them
tempFile = saveTempfile(models)
// maybe exclude the ones we do not yet have coverage
diff = gitDiff(tempFile, './mode_list.json')

if (!diff) {
  throw new Error(diff);
}

maybe gron

▶ diff <(gron two.json) <(gron two-b.json)
3c3
< json.contact.email = "mail@tomnomnom.com";
---
> json.contact.email = "contact@tomnomnom.com";

async function fetchRemoteModels(url: string): Promise<LiteLLMModelList> {
return new Promise((resolve, reject) => {
https
.get(url, (res) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

curious why the use of https module vs. fetch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AI generated :)

"tsup": "^8.4.0",
"typescript": "5.5.4",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.1.9"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we add a few scripts in package.json or use/update Makefile? will we break CI/CD if we find discrepancies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we should eventually but not yet

supports_reasoning: z.boolean().optional(),
supports_web_search: z.boolean().optional(),
search_context_cost_per_query: searchContextCostPerQuerySchema,
deprecation_date: z.string().optional(), // YYYY-MM-DD
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would be nice if there was a published/created date. I recently rearranged our Gemini models to help users to select the most recent model and to have them clustered together (esp. that we vertex ai may have more than just gemini, for example).

image

vs.

(in my PR)
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agree, unfortunately the litellm registry does not have this as far as i can tell

import { ModelSchema, ModelSpec } from "../schema/models";

// Zod schema for individual model details
const searchContextCostPerQuerySchema = z
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#nit would be nice to move lite related things to a litellm.ts with explicit interface (would help with readability/maintainability) esp. that you can reduce the mention of LiteLLM in the variable name, for example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

maybe. i think it's also worth optimizing for ease of AI-maintainability of this file

}
}

function translateLiteLLMToBraintrust(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#nit toBraintrustModelName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

}

if (provider === "gemini") {
if (modelName.startsWith("gemini/gemini-gemma-")) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would be nice to add this to the schema to try to detect if litellm changes the json under us

i.e. assert that the models may start with xai etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that will just show up in the discrepancies

}

async function findMissingCommand(argv: any) {
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#nit

  • could catch in the main()?
  • would be nice to break up the function
  • would be nice if the function signature was explicit i.e. call the function with the actual arguments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

eh i think i'd rather just keep to the AI generated code


if (allPresentProviders.length > 0) {
console.log("\n--- Providers with All Models Present ---");
for (const provider of allPresentProviders) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unnecesary if statement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it prevents the console.log

const modelDetail = remoteModels[remoteModelName];

if (argv.provider) {
const lowerArgProvider = argv.provider.toLowerCase();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#nit "provider" (and lowerArgProvider) are a bit vague/indirect

may be more readable if it we wrote the code as searchProvider

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think i prefer to keep as is for literal argument parsing

const modelProvider = modelDetail.litellm_provider?.toLowerCase();
const modelNameProviderPart = remoteModelName
.split("/")[0]
.toLowerCase();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same for remoteModelName might as well call that litellmModel

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i'd prefer to keep as is

This is computed by running

```
cd packages/proxy
npx tsx scripts/sync_models.ts check-prices --write
```
@ankrgyl Ankur Goyal (ankrgyl) merged commit 1d8a64a into main May 19, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants