Example: GitHub Actions
Copy-paste this workflow into
.github/workflows/ai-review.yml. Update the project slug and review script path.
What This Does
A GitHub Actions workflow that runs an AI code review on every pull request, tracking the time and token cost in Keito.
Prerequisites
KEITO_API_KEYstored as a GitHub secretKEITO_ACCOUNT_IDstored as a GitHub secretPROJECT_SLUGset as a GitHub variable- An AI review script at
./scripts/ai-review.sh
Full Code
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
env:
KEITO_API_KEY: ${{ secrets.KEITO_API_KEY }}
KEITO_ACCOUNT_ID: ${{ secrets.KEITO_ACCOUNT_ID }}
steps:
- uses: actions/checkout@v4
- name: Install Keito CLI
run: npm install -g @keito/cli
- name: Start tracking
run: |
keito time start \
--project ${{ vars.PROJECT_SLUG }} \
--task code-review \
--source agent \
--agent-id "gh-actions-reviewer" \
--session-id "${{ github.run_id }}"
- name: Run AI code review
id: review
run: |
./scripts/ai-review.sh > review-output.txt 2>&1
echo "token_count=$(grep -oP 'tokens: \K[0-9]+' review-output.txt || echo 0)" >> $GITHUB_OUTPUT
- name: Stop tracking and log cost
if: always()
run: |
keito time stop \
--notes "AI code review for PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"
if [ "${{ steps.review.outputs.token_count }}" -gt 0 ]; then
keito expense log \
--project ${{ vars.PROJECT_SLUG }} \
--quantity ${{ steps.review.outputs.token_count }} \
--notes "Code review tokens for PR #${{ github.event.pull_request.number }}"
fi
How It Works
- Triggers on every pull request.
- Installs the Keito CLI from npm.
- Starts a timer with the GitHub run ID as the session ID.
- Runs your AI review script and captures the token count from output.
- Stops the timer and logs an LLM expense (if tokens were used).
- The
if: always()ensures tracking stops even if the review step fails.
Customisation
- Multiple reviewers: Run different AI tools in parallel steps, each with their own
agent-id. - Comment on PR: Add a step to post the review output as a PR comment using
gh pr comment. - Branch filtering: Add
branches: [main]to only review PRs targeting main.