name: Sync model prices

# Pulls the latest LiteLLM community price registry every day and opens
# a pull request when prices have drifted.  The release workflow ships
# whatever's currently in src/pricing_data.rs, so merging the auto-PR
# before cutting a tag picks up the freshest pricing.

on:
  schedule:
    - cron: "37 6 * * *"   # daily at 06:37 UTC
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Regenerate src/pricing_data.rs from LiteLLM
        run: python3 scripts/sync_prices.py

      - name: Open PR if prices drifted
        uses: peter-evans/create-pull-request@v7
        with:
          branch: chore/sync-prices
          base: main
          title: "chore: sync model price table"
          body: |
            Automated weekly sync of `src/pricing_data.rs` from
            [LiteLLM's model_prices_and_context_window](https://github.com/BerriAI/litellm/blob/main/litellm/model_prices_and_context_window_backup.json).

            Merge to refresh the bundled price table.  Cost estimates
            shipped in the next tagged release will reflect these prices.
          commit-message: "chore: sync model price table"
          delete-branch: true
          add-paths: src/pricing_data.rs
