name: Refresh Anthropic rate card

on:
  schedule:
    - cron: "0 6 * * 1"  # Monday 06:00 UTC
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  refresh:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Refresh anthropic_rates.json
        working-directory: autogpt_platform/backend
        run: python scripts/refresh_anthropic_rates.py

      - name: Open PR with refreshed rates
        uses: peter-evans/create-pull-request@v6
        with:
          branch: chore/refresh-anthropic-rates
          base: dev
          title: "chore(backend): refresh Anthropic rate card from LiteLLM"
          commit-message: "chore(backend): refresh anthropic_rates.json from LiteLLM upstream"
          body: |
            Weekly refresh of `autogpt_platform/backend/backend/copilot/anthropic_rates.json`
            from LiteLLM's `model_prices_and_context_window_backup.json`.

            Filtered to `claude*` / `anthropic/claude*` entries.

            Auto-generated by `.github/workflows/refresh-anthropic-rates.yml`.
          add-paths: |
            autogpt_platform/backend/backend/copilot/anthropic_rates.json
