Skip to content

fix: fall back to OPENROUTER_API_KEY for Anthropic base URL - #4

Open
ryan953 wants to merge 1 commit into
boldsoftware:mainfrom
ryan953:openrouter-anthropic-fallback
Open

fix: fall back to OPENROUTER_API_KEY for Anthropic base URL#4
ryan953 wants to merge 1 commit into
boldsoftware:mainfrom
ryan953:openrouter-anthropic-fallback

Conversation

@ryan953

@ryan953 ryan953 commented Aug 4, 2026

Copy link
Copy Markdown

NewAnthropicFromEnv now falls back to OPENROUTER_API_KEY for the x-api-key
header when ANTHROPIC_BASE_URL is set but ANTHROPIC_API_KEY isn't. OpenRouter's
Anthropic-compatible endpoint (https://openrouter.ai/api) accepts an OpenRouter
key over that same header, so this lets meat run there using an existing
OPENROUTER_API_KEY + ANTHROPIC_BASE_URL shell setup with no separate
ANTHROPIC_API_KEY needed. An explicit ANTHROPIC_API_KEY still always wins, and
OPENROUTER_API_KEY alone (without ANTHROPIC_BASE_URL) does not trigger the
fallback.

Note this only applies once meat is already on the Anthropic code path, which
requires MEAT_MODEL/-model to name a claude-* model — otherwise meat's
model resolution defaults to OpenAI.

Added tests covering the new fallback, the explicit-key precedence, and the
no-ANTHROPIC_BASE_URL guard.

When ANTHROPIC_BASE_URL is set (e.g. OpenRouter's Anthropic-compatible
endpoint at https://openrouter.ai/api) but ANTHROPIC_API_KEY isn't,
use OPENROUTER_API_KEY for the x-api-key header instead of erroring
out. OpenRouter's Anthropic skin accepts an OpenRouter key over that
header. Requires MEAT_MODEL/-model to name a Claude model so meat
takes the Anthropic code path rather than its OpenAI default.
@ryan953
ryan953 marked this pull request as ready for review August 4, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant