This script tests OpenRouter models for native OpenAI function calling support and provides utilities to list models and their endpoints.
- Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh- Install dependencies (automatically creates venv with Python 3.12):
uv sync --python 3.12- Set your OpenRouter API key:
export OPENROUTER_API_KEY="your_api_key_here"uv run python openrouter_test.py --list-modelsuv run python openrouter_test.py --list-endpointsuv run python openrouter_test.py --test-function-calling --model "anthropic/claude-3-sonnet"uv run python openrouter_test.py --test-function-calling --model "anthropic/claude-3-sonnet" --provider "anthropic"uv run python openrouter_test.py --test-structured-output --model "openai/gpt-4o"uv run python openrouter_test.py --test-structured-output --model "openai/gpt-4o" --provider "openai"uv run python openrouter_test.py --list-endpoints --required-parameters "tools,response_format,max_tokens"uv run python openrouter_test.py --test-all-modelsuv run python openrouter_test.py --test-all-models --limit 10 --save results.jsonuv run python openrouter_test.py --test-all-models --concurrency 16 --timeout 30 --save results.jsonThe script tests two key OpenAI API features:
- Defines a
get_weatherfunction with JSON schema - Sends a weather-related query to the model
- Checks if the model responds with proper function calls
- Records success/failure and any errors
- Tests
response_formatwithtype: "json_schema"andstrict: true - Defines a weather response schema with required fields
- Verifies the model returns valid JSON matching the schema
- Optionally enforces specific providers using the
providerparameter - Useful for testing provider-specific implementations
- Concurrent model testing: Test up to 8 models simultaneously (configurable via
--concurrency) - Sequential endpoint testing: Within each model, endpoints are tested sequentially for clear progress tracking
- Automatic timeout handling: Configurable request timeouts prevent hanging on unresponsive endpoints
- Incremental saving: Results are saved after each completed model to prevent data loss
- Capability-aware testing: Only tests function calling when
toolsparameter is supported - Endpoint validation: Only tests structured output when
response_formatparameter is supported - Efficient skipping: Avoids unnecessary API calls to unsupported endpoints
- ✅ Model supports function calling and used it correctly
⚠️ Model responded but didn't use function calling- ❌ Model failed with an error
Results can be saved to JSON files for further analysis.