Per-request model selection, a feature for pydantic-ai-app-factory
pip install pydantic-ai-model-selection Copy PIP instructions
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.
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.
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.
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.
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.
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.
All 2 files in this release have provenance metadata.
agent app-factory fastapi feature model-selection pydantic-ai
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
All 2 files in this release have been uploaded with provenance metadata.
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.




