OpenAI-compatible mock server for testing LLM integrations.
- OpenAI API compatibility with key endpoints (
/v1/models,/v1/chat/completions,/v1/responses) - Configurable mock responses via strategies
- Default mirror strategy (echoes input as output)
- Streaming support for both Chat Completions and Responses APIs
docker container run -p 8000:8000 ghcr.io/modai-systems/llmock:latestTest with this sample request (yes, the default secret key is really your-secret-api-key):
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-secret-api-key" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'What the request does is simply mirror the input, so it returns Hello!.
Prerequisites:
- Python 3.14+
- uv (package manager)
Installation:
git clone https://github.com/modAI-systems/llmock.git
cd llmock
uv sync --all-extrasRun the Server:
uv run uvicorn llmock.app:app --host 0.0.0.0 --port 8000For development with auto-reload:
uv run uvicorn llmock.app:app --host 0.0.0.0 --port 8000 --reloadThe server will be available at http://localhost:8000. Health check available at /health.
Point your OpenAI client to the mock server:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="mock-key" # Any key works
)
# Chat Completions API
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
# Responses API
response = client.responses.create(
model="gpt-4o",
input="Hello!"
)
print(response.output[0].content[0].text)Edit config.yaml to configure available models:
models:
- id: "gpt-4o"
created: 1715367049
owned_by: "openai"
- id: "gpt-4o-mini"
created: 1721172741
owned_by: "openai"uv run pytest -vuv run ruff format src tests # Format code
uv run ruff check src tests # Lint code- Architecture: See docs/ARCHITECTURE.md
- Decisions: See docs/DECISIONS.md
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests and linting (
uv run pytest && uv run ruff check src tests) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.