|
| 1 | +name: Sync LLM pricing |
| 2 | + |
| 3 | +# Daily refresh of `data/llm_pricing.json` from LiteLLM's price table. Filtered down to |
| 4 | +# OpenAI / Anthropic chat models and converted from per-token to per-million-tokens so the |
| 5 | +# splashboard runtime can consume it without rescaling. Opens a PR on diff; never commits |
| 6 | +# straight to main — agent PRs always wait for a human merge per repo policy. |
| 7 | + |
| 8 | +on: |
| 9 | + schedule: |
| 10 | + - cron: '0 0 * * *' # daily 00:00 UTC |
| 11 | + workflow_dispatch: # manual trigger |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + sync: |
| 19 | + name: Refresh pricing snapshot |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v6 |
| 23 | + |
| 24 | + - name: Fetch upstream LiteLLM table |
| 25 | + run: | |
| 26 | + curl -sSf -o /tmp/litellm.json \ |
| 27 | + "https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/model_prices_and_context_window_backup.json" |
| 28 | +
|
| 29 | + - name: Extract OpenAI + Anthropic chat models |
| 30 | + run: | |
| 31 | + python3 <<'PY' |
| 32 | + import json |
| 33 | + src = json.load(open('/tmp/litellm.json')) |
| 34 | + out = {} |
| 35 | + for model, v in src.items(): |
| 36 | + if not isinstance(v, dict): |
| 37 | + continue |
| 38 | + if v.get('litellm_provider') not in ('openai', 'anthropic'): |
| 39 | + continue |
| 40 | + if v.get('mode') != 'chat': |
| 41 | + continue |
| 42 | + if v.get('input_cost_per_token') is None and v.get('output_cost_per_token') is None: |
| 43 | + continue |
| 44 | + row = { |
| 45 | + 'input': v.get('input_cost_per_token', 0.0) * 1_000_000, |
| 46 | + 'output': v.get('output_cost_per_token', 0.0) * 1_000_000, |
| 47 | + 'cache_read': v.get('cache_read_input_token_cost', 0.0) * 1_000_000, |
| 48 | + } |
| 49 | + cw5 = v.get('cache_creation_input_token_cost', 0.0) * 1_000_000 |
| 50 | + cw1 = v.get('cache_creation_input_token_cost_above_1hr', 0.0) * 1_000_000 |
| 51 | + if cw5: |
| 52 | + row['cache_write_5m'] = cw5 |
| 53 | + if cw1: |
| 54 | + row['cache_write_1h'] = cw1 |
| 55 | + out[model] = row |
| 56 | +
|
| 57 | + out_sorted = {k: out[k] for k in sorted(out)} |
| 58 | + final = { |
| 59 | + "_meta": { |
| 60 | + "source": "https://raw.githubusercontent.com/BerriAI/litellm/main/litellm/model_prices_and_context_window_backup.json", |
| 61 | + "filter": "litellm_provider in {openai, anthropic} AND mode == chat", |
| 62 | + "fields": "USD per 1M tokens", |
| 63 | + }, |
| 64 | + "models": out_sorted, |
| 65 | + } |
| 66 | + json.dump(final, open('data/llm_pricing.json', 'w'), indent=2, sort_keys=False) |
| 67 | + print(f"rows: {len(out_sorted)}") |
| 68 | + PY |
| 69 | +
|
| 70 | + - name: Open PR if diff |
| 71 | + uses: peter-evans/create-pull-request@v7 |
| 72 | + with: |
| 73 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + branch: chore/sync-llm-pricing |
| 75 | + title: 'chore: sync llm pricing from LiteLLM' |
| 76 | + commit-message: | |
| 77 | + chore: sync llm pricing from LiteLLM |
| 78 | +
|
| 79 | + Automated daily refresh of `data/llm_pricing.json`. Diff reviews |
| 80 | + catch upstream schema or value changes before they reach users. |
| 81 | + body: | |
| 82 | + Automated daily refresh of `data/llm_pricing.json` from LiteLLM's price table. |
| 83 | +
|
| 84 | + **Review checklist:** |
| 85 | + - [ ] Diff is plausible (no order-of-magnitude jumps that aren't matched by a public Anthropic / OpenAI announcement) |
| 86 | + - [ ] No models silently disappeared (would zero-cost their token counts) |
| 87 | + - [ ] `cargo test fetcher::llm_pricing::tests::snapshot_parses_repo_seed` passes — guards schema drift |
| 88 | + labels: | |
| 89 | + automation |
| 90 | + pricing |
| 91 | + delete-branch: true |
0 commit comments