Creating Your First AIPerf Plugin
This tutorial walks you through creating a custom AIPerf endpoint plugin from scratch. By the end, you’ll have a working plugin package that can benchmark any custom API.
Contributing directly to AIPerf? The endpoint class (Step 2) and manifest format (Step 3) are the same, but you can skip the external packaging:
- Add your class under
src/aiperf/instead of a separate package - Register it in the existing
src/aiperf/plugin/plugins.yamlinstead of creating a new one - Skip: Project Structure, Step 1 (pyproject.toml/entry points), Step 4 (install)
What You’ll Build
We’ll create a plugin for a hypothetical “Echo API” that returns the input text with some metadata. This simple example demonstrates all the core concepts you need to build more complex plugins.
Prerequisites
- Python 3.10+
- AIPerf installed (
pip install aiperf) - Basic understanding of Python async/await and Pydantic
Key Concepts
Before diving in, understand the plugin system terminology:
What you’re building:
For complete plugin system documentation, see the Plugin System Reference.
Project Structure
Create a new directory for your plugin package:
You should see:
Now fill in each file in the steps below.
Step 1: Create the Project Files
pyproject.toml
The key part is the [project.entry-points."aiperf.plugins"] section - this tells AIPerf where to find your plugin manifest.
src/my_plugins/init.py
src/my_plugins/endpoints/init.py
Step 2: Create the Endpoint Class
src/my_plugins/endpoints/echo_endpoint.py
Your endpoint needs two methods: format_payload() and parse_response().
What’s happening:
format_payload()converts AIPerf’sRequestInfointo your API’s format.parse_response()extracts the response text into aParsedResponse.
Step 3: Create the Plugin Manifest
src/my_plugins/plugins.yaml
Step 4: Install Your Plugin
From your plugin directory, install into the same Python environment where AIPerf is installed. AIPerf discovers plugins via entry points, which only works when both packages share the same environment.
You should see:
Important: If you use
uv, virtual environments, or conda, make sure you activate the environment where AIPerf is installed before runningpip install.
Step 5: Verify Installation
Confirm both packages are installed in the same environment:
You should see both packages listed in the same environment:
Check that AIPerf discovers your plugin:
You should see your plugin in the table:
You should see:
You should see:
Step 6: Create a Test Server
To test your plugin end-to-end, create a minimal Echo API server. Save this as echo_server.py in your project root:
Start the server:
You should see:
Step 7: Use Your Plugin
With the test server running, use your endpoint with AIPerf:
You should see:
Step 8: Add Tests
tests/test_echo_endpoint.py
Fixtures: Create
conftest.pywithmock_model_endpoint,mock_request_info, andmock_responsefixtures. See AIPerf’s test utilities for examples.
Understanding the Code
Component Summary
Data Flow
Response Types
Metadata Fields
Next Steps
Troubleshooting
Plugin not found
Solutions:
- Ensure
pip install -e .completed successfully - Check the entry point in
pyproject.tomlmatches your package structure - Run
aiperf plugins --validateto check for errors
Import errors
Solutions:
- Verify the class path format:
module.path:ClassName - Check all imports in your endpoint file work:
python -c "from my_plugins.endpoints.echo_endpoint import EchoEndpoint" - Ensure all dependencies are installed
Response parsing fails
Solutions:
- Use
-vvflag to see raw responses in debug logs - Check that your
parse_responsehandles your API’s actual response format - Use
auto_detect_and_extract()as a fallback for unknown formats
Reference
- Plugin System Documentation - Complete plugin system reference
- Template Endpoint Tutorial - Using templates for custom payloads