Skip to content

Fail fast on invalid OpenRouter model names#39

Open
ScuttleBot wants to merge 2 commits intomainfrom
scuttlebot/fail-fast-bad-model
Open

Fail fast on invalid OpenRouter model names#39
ScuttleBot wants to merge 2 commits intomainfrom
scuttlebot/fail-fast-bad-model

Conversation

@ScuttleBot
Copy link

Problem

Running a benchmark with a typo'd model name (e.g. anthropic/claude-sonet-4 instead of claude-sonnet-4) wastes a full benchmark run that just scores 0% on every task.

Solution

Validate the model ID against OpenRouter's /api/v1/models endpoint before running any tasks.

Features

  • Queries OpenRouter API to check if model exists
  • Suggests close matches if model name looks like a typo
  • Lists available models from the same provider as hints
  • Gracefully skips validation if OPENROUTER_API_KEY not set or API errors
  • Exits immediately with code 1 if model is invalid

Example Output

❌ Model 'anthropic/claude-sonet-4' not found on OpenRouter.
   Did you mean: anthropic/claude-sonnet-4?

Or for completely wrong names:

❌ Model 'anthropic/gpt-5' not found on OpenRouter.
   Available anthropic models: anthropic/claude-3-opus, anthropic/claude-3-sonnet, anthropic/claude-sonnet-4, ...

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 9, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The PR adds a validate_openrouter_model() function that checks whether a given model ID exists on OpenRouter before running the benchmark. This is a well-structured fail-fast mechanism that:

  • Tries the specific model endpoint first (fast path), falling back to the full catalog only on 404
  • Gracefully handles network/API errors by skipping validation rather than blocking
  • Provides helpful "did you mean" suggestions for typos
  • Is properly integrated into benchmark.py with clean error handling

The error handling is thorough, covering HTTPError, URLError, and JSONDecodeError. The API key is transmitted securely over HTTPS. The code follows existing patterns in the codebase.

Files Reviewed (2 files)
  • scripts/lib_agent.py - New ModelValidationError class and validate_openrouter_model() function
  • scripts/benchmark.py - Integration of model validation before benchmark execution

Validates model ID against OpenRouter's /api/v1/models endpoint before
running any tasks. This prevents wasting compute on a full benchmark run
that will just score 0% because the model doesn't exist.

Features:
- Queries OpenRouter API to check if model exists
- Suggests close matches if model name looks like a typo
- Lists available models from the same provider as hints
- Gracefully skips validation if API key not set or API errors
- Exits with error code 1 immediately if model is invalid

Example output for typo:
  ❌ Model 'anthropic/claude-sonet-4' not found on OpenRouter.
     Did you mean: anthropic/claude-sonnet-4?
1. Check specific model endpoint first (/api/v1/models/{id}) for fast path
   - Only fetches full catalog when model not found (for suggestions)
   - Reduces latency in happy path

2. Filter None values from model_ids set
   - Prevents None from leaking into 'Did you mean' suggestions
@olearycrew olearycrew force-pushed the scuttlebot/fail-fast-bad-model branch from 4a4fdc6 to 31a714b Compare March 11, 2026 14:01
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.

2 participants