Transcribe through OpenRouter when OPENROUTER_API_KEY is set

A Claude subscription can't be used by the app, so let it use any cheap
vision model on OpenRouter instead (default google/gemini-3.1-flash-lite,
OPENROUTER_MODEL to change). The Anthropic API stays available as the
second choice. Both providers share the prompt and live behind one
{ name, model, transcribe } interface in server/providers.mjs; OpenRouter
retries 408/429/5xx and network errors and turns 401/402/404 into
messages the editor can show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
This commit is contained in:
agent 2026-11-04 15:38:24 +00:00
parent 46aa1236ed
commit f353c14619
11 changed files with 258 additions and 91 deletions

View file

@ -1,13 +1,21 @@
# Copy to .env (chmod 600) and fill in. Never commit .env.
# API key from https://platform.claude.com (Anthropic API, billed separately from a Claude subscription).
# Without it the app still works; uploaded photos just have to be typed up by hand.
# Transcription of page photos. Set ONE of the two keys; OpenRouter wins if both are set.
# Without either the app still works; uploaded photos just have to be typed up by hand.
# OpenRouter key from https://openrouter.ai/settings/keys (prepaid credit).
OPENROUTER_API_KEY=
# Any OpenRouter model that accepts images. Default ~$0.0015 a page; google/gemini-2.5-flash-lite
# is cheaper (~$0.0005), anthropic/claude-haiku-5.5 or google/gemini-3.5-flash read hard pages better.
OPENROUTER_MODEL=google/gemini-3.1-flash-lite
# Or: Anthropic API key from https://platform.claude.com (billed separately from a Claude subscription).
ANTHROPIC_API_KEY=
# Password people need to add and edit plays. Without it uploading is switched off.
UPLOAD_PASSWORD=
# Vision model used for transcription. claude-sonnet-5-5 reads hard pages better at ~20x the price.
# Claude model when using ANTHROPIC_API_KEY. claude-sonnet-5-5 reads hard pages better at ~20x the price.
CLAUDE_MODEL=claude-haiku-5-5
# Safety cap on pages transcribed per day (all users together), and pages per play.