Per-Request Model Selection for Pydantic AI Apps
pydantic-ai-model-selection is a feature for
pydantic-ai-app-factory that lets a client pick
the model for one run from a list the operator fixes at startup. It validates the choice at the
boundary, can restrict options per user, and serves the list a frontend dropdown reads.
Quick Start
Install the package:
pip install pydantic-ai-model-selection "pydantic-ai-slim[openai]"
Create a file main.py with:
from pydantic_ai_app_factory import UserContext, create_agent, create_agent_app
from pydantic_ai_model_selection import ModelOption, ModelSelection
def auth() -> UserContext:
return UserContext(user_id='demo')
selection = ModelSelection(
options={
'fast': ModelOption('openai:gpt-5-mini', label='Fast'),
'thorough': ModelOption('openai:gpt-5'),
},
)
agent = create_agent('openai:gpt-5-mini', instructions='You are a helpful assistant.')
app = create_agent_app(agent, auth=auth, features=[selection])
A request that names no model runs on the agent's own model. Set OPENAI_API_KEY in the
environment; a missing provider key fails startup.
Launch it like any other FastAPI app:
pip install "fastapi[standard]"
fastapi dev
A request names its model as a top-level field on /chat, or under extras on /run:
curl -N http://127.0.0.1:8000/chat \
-H 'Content-Type: application/json' \
-d '{"id": "test-1", "trigger": "submit-message", "model": "thorough", "messages": [{"id": "m1", "role": "user", "parts": [{"type": "text", "text": "Hello"}]}]}'
GET /model-selection/models returns the options this caller may pick, with their labels.
Documentation
Model selection
covers the options, per-user restrictions, the listing route, use without create_agent_app, and the
reference. It builds on the factory's
Features.
Motivation
Pydantic AI can already pick a model per run through a capability's
get_model(), and its models
share one interface across providers. So the options can mix OpenAI, Google and a self-hosted
gateway, and this package only wraps the hook as an app-factory feature.
Contributing
Contributions under Apache-2.0 are welcome; please open an issue first. make install sets up the
environment and make all must pass before a commit. Conventions are in
AGENTS.md.
License
Metadata
Release files for pydantic-ai-model-selection 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydantic_ai_model_selection-0.1.0.tar.gz | 16.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_ai_model_selection-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.4 kB
Release files / pydantic_ai_model_selection-0.1.0.tar.gz
| Download URL | pydantic_ai_model_selection-0.1.0.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a60cfc5287a7871835b904eb78d39c361c821e6470cd0ff2fdda336f3800649
|
|
BLAKE2b-256 checksum How to use checksums |
deef60460e9bc1f7173a454bfcd81271b51fccddc284fbac5c5ee60f937bf60f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logRelease files / pydantic_ai_model_selection-0.1.0-py3-none-any.whl
| Download URL | pydantic_ai_model_selection-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb3bccb3e8104d2ca85f91618858f9977d655e79b0aec21c99335ae210c87707
|
|
BLAKE2b-256 checksum How to use checksums |
9034c43dba53601534b40ef3a43b8900383b4d62d3e51caecf6d49c78b3fc04c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logSecurity for pydantic-ai-model-selection 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pydantic_ai_model_selection-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.