The four choices
The API lowercases
voteChoice. The arena also sends voteDurationMs: the time between the answers appearing and the click.
Recording a vote
- The voter is the
subclaim of the bearer token. - Comparisons are read through
v_comparisons_masked, a view that masks model identities until a comparison is revealed. - One vote per user per comparison. The code relies on a unique constraint on
model_votes (comparison_id, user_id)for this, so a second vote fails with500 VOTE_ERROR. Make sure the constraint exists in every environment (see Supabase setup). - Any database error comes back as
500 VOTE_ERRORwith the message inerror.
The arena hides model names until the vote, and after a
left or right vote it shows only the winning answer with a toggle for the other. Both names are already in the dualchat response; hiding them is the client’s job.ELO and the leaderboard
The API never computes ratings. They live in the database:1
model_leaderboard
One row per model:
elo_score (starts at 1000), total_wins, total_losses, total_ties, total_comparisons, updated_at.2
calculate_elo_update(winner_elo, loser_elo, is_tie, k_factor = 32)
A Postgres function with the standard Elo update: expected score
1 / (1 + 10^((opponent − self) / 400)), actual score 1, 0 or 0.5 for a tie, and K = 32.3
v_leaderboard
Joins
ai_models (active only) with model_leaderboard, computes win_rate = total_wins / total_comparisons × 100 (two decimals) and elo_rank = RANK() OVER (ORDER BY elo_score DESC).Try the maths
The calculator uses the same formula ascalculate_elo_update: expected score from the rating gap, K = 32, each side’s change rounded to a whole number.
The live leaderboard
GET /api/arena/model-stats returns the view as { success, items }. Each item carries camelCase fields (modelName, eloScore, eloRank, winRate, …) and snake_case aliases (model_name, elo_rating, elo, win_rate, total_matches, …) because the arena, the admin panel and the Telegram bot grew up reading different names.
Example item (illustrative values)
Cloudflare Workers AI models were seeded into
model_leaderboard in March 2026 with starting scores between 950 and 1050. Ties in elo_score share a rank, which is why the leaderboard can show two models at the same position.Related
Submit a vote (API)
Request and response reference.
Votes (admin API)
Search, inspect and remove votes.