A comprehensive Python tool for benchmarking Large Language Model (LLM) APIs. This tool measures key performance metrics including generation speed, prompt throughput, time to first token (TTFT), and success rates across different concurrency levels.
- Concurrent API Testing: Test multiple concurrency levels simultaneously
- Comprehensive Metrics: Measure generation speed, prompt throughput, TTFT, and success rates
- Multiple Output Formats: Support for console tables, JSON, and YAML output
- Flexible Configuration: Custom prompts or auto-generated random prompts
- Network Latency Measurement: Built-in latency testing to API endpoints
- Rich Console Output: Beautiful tables and progress indicators
- Python 3.11 or higher
- pip package manager
git clone <repository-url>
cd llmbench
pip install -e .pip install -e ".[dev]"llmbench --base-url https://api.openai.com/v1 --api-key sk-your-key-herellmbench \
--base-url https://api.example.com/v1 \
--api-key sk-your-key \
--model gpt-4 \
--concurrency 1,2,4,8 \
--max-tokens 512 \
--prompt "Write a short story about AI" \
--format json--base-url: API endpoint base URL (required)--api-key: API authentication key--model: Model name (auto-discovered if not provided)--concurrency: Comma-separated concurrency levels (default: 1)--max-tokens: Maximum tokens to generate (default: 512)--prompt: Custom prompt text--num-words: Number of random words for prompt generation (default: 100)--format: Output format (json, yaml, or console table)
Tokens generated per second, calculated as total output tokens divided by response time minus network latency.
Tokens processed per second for input prompts, measured from request start to first token.
Time from request initiation to receiving the first token, in seconds.
Percentage of successful API calls out of total attempts.
Rich-formatted table with summary information and detailed metrics per concurrency level.
Structured JSON output containing all benchmark data.
Human-readable YAML format with complete results.
All formats automatically save a Markdown file (benchmark_results.md) with the results.
The tool is organized into the following modules:
cli/: Command-line interface and output formattingcore/api/: API client and prompt generation utilitiescore/utils/: Performance measurement utilitiescore/: Constants and exception definitions
pytest# Format code
black src/
# Lint code
ruff check src/
# Type checking
mypy src/llmbench/
├── src/
│ ├── cli/
│ │ ├── main.py # CLI entry point
│ │ ├── models.py # Data models
│ │ ├── benchmark.py # Benchmark orchestration
│ │ └── formatters.py # Output formatting
│ └── core/
│ ├── api/
│ │ ├── client.py # OpenAI API client
│ │ └── prompts.py # Prompt generation
│ ├── utils/
│ │ ├── latency.py # Network latency measurement
│ │ └── speed.py # Performance metrics
│ ├── constants.py # Application constants
│ └── exceptions.py # Custom exceptions
├── tests/ # Unit tests
├── pyproject.toml # Project configuration
└── README.md # This file
This tool is designed to work with OpenAI-compatible APIs. It has been tested with:
- OpenAI API
- Compatible local LLM servers (e.g., vLLM, Ollama with OpenAI compatibility)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the GNU General Public License version 3 - see the LICENSE file for details.
For issues, questions, or contributions, please open an issue on the GitHub repository.